Closed trunglv closed 3 years ago
Hi @trunglv. Thank you for your report. To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue: @magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @trunglv
Thank you for your report
Can you please provide more details about the steps to reproduce with, screenshots attached? It's not clear how is the double attribute created and searched for. In this way, we could faster reproduce the issue and provide a fix for it
Thank you in advance
Hi @engcom-Bravo It seems a problem will happen if we set a decimal attribute to be searchable. Here is what I debugged:
Class : Magento\Elasticsearch\SearchAdapter\Query\Builder\Match => function buildQueries
$attributeAdapter = $this->attributeProvider->getByAttributeCode($resolvedField);
$fieldType = $this->fieldTypeResolver->getFieldType($attributeAdapter);
A variable $fieldType is returned a value is "double", should be "float"
class : Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Resolver\CompositeResolver class : Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Resolver\FloatType
if ($attribute->isFloatType()) {
return $this->fieldTypeConverter->convert(ConverterInterface::INTERNAL_DATA_TYPE_FLOAT);
}
class Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Converter
private $mapping = [
self::INTERNAL_DATA_TYPE_STRING => self::ES_DATA_TYPE_STRING,
self::INTERNAL_DATA_TYPE_KEYWORD => self::ES_DATA_TYPE_STRING,
self::INTERNAL_DATA_TYPE_FLOAT => self::ES_DATA_TYPE_DOUBLE,
self::INTERNAL_DATA_TYPE_INT => self::ES_DATA_TYPE_INT,
self::INTERNAL_DATA_TYPE_DATE => self::ES_DATA_TYPE_DATE,
];
You can see variable mappings: It mapped "float" => double. So it's a problem I think.
Hello @trunglv
I have rechecked the issue on the latest 2.4-develop with the following settings Catalog Input Type for Store Owner - Text field Input Validation for Store Owner - Decimal Number Use in Search - Yes Visible in Advanced Search - Yes
I have created a Simple product and added the previously created attribute to it
I can perform search on Storefront via attribute value and via Title. No error appears in log
Can you please confirm that you are able to reproduce the issue on 2.4-develop?
Thank you
Hello @trunglv Agree with @engcom-Bravo
After following steps mentioned by you, product is showing in search list, so can you provide more information
Please review screenshot.
Hi @krishprakash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @trunglv. Feel free to reopen/comment once you confirm that issue reproduce on 2.4-develop instance Thanks!!
I'm getting exactly the same problem. I wasn't actually aware I had so many attributes searchable (141!) so it will be difficult to track down which is the problem attribute, but this only occurred after upgrade from 2.3 to 2.4 and change from mysql to elasticsearch catalog search engine. The elasticsearch error is:
Caused by: java.lang.NumberFormatException: For input string: "BEKO"
at jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054) ~[?:?]
at jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110) ~[?:?]
at java.lang.Double.parseDouble(Double.java:549) ~[?:?]
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType.objectToDouble(NumberFieldMapper.java:876) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType.access$200(NumberFieldMapper.java:173) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$3.parse(NumberFieldMapper.java:369) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$3.termQuery(NumberFieldMapper.java:388) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberFieldType.termQuery(NumberFieldMapper.java:928) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.search.MatchQuery$MatchQueryBuilder.lambda$newTermQuery$1(MatchQuery.java:576) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.search.MatchQuery$MatchQueryBuilder.newTermQuery(MatchQuery.java:579) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.search.MatchQuery.parse(MatchQuery.java:277) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.MatchQueryBuilder.doToQuery(MatchQueryBuilder.java:426) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:99) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:394) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:380) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:99) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:334) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:346) ~[elasticsearch-7.6.2.jar:7.6.2]
And the corresponding entry in magento log:
}\",\"index_uuid\":\"rgbnzqW-SViJjs7WwTy-yg\",\"index\":\"magento2_product_1_v6\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"BEKO\\\"\"}}}]},\"status\":400} at /srv/www/dev.www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []
Magento: 2.4.1 opensource.
OK this was actually pretty easy to track down. Look for eav_attribute.backend_type ='decimal' and change 'Use in Search' to 'No' for each attribute:
After this, the search works as expected.
I faced the same issue. In my case attribute wasn't created using UI. Decimal attributes there created as backend_type = varchar, frontend_input = text In my case I made the following: backend_type = decimal, frontend_input = text [optional input validation]
i got same issue. how about update it, hello @trunglv
Pls check my quick fix - It may help https://github.com/betagento/magento2_search_fixing
Pls check my quick fix - It may help https://github.com/betagento/magento2_search_fixing
thanks @trunglv , i tried but it's not working for me. hot fix i have to set config "use in search" to No
Pls check my quick fix - It may help https://github.com/betagento/magento2_search_fixing
thanks @trunglv , i tried but it's not working for me. hot fix i have to set config "use in search" to No
It worked on my customer website. Hope you have already done necessary commands for it : setup-upgrade, Di Compile -- Cache so on ... -- Anyway Thanks for trying. I will try it to another place
i am using magento 2.4.0
i create an attribute
i can typing the number to the search box and it's working
but if i typing the string/text to the search box, it's not work
already got the error
Exception #0 (Elasticsearch\Common\Exceptions\BadRequest400Exception): {"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: For input string: \"xxx\"","index_uuid":"4Z6fNLOJT9mTqJ6KP9Py2Q","index":"magento2_homepro_product_2_v2"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"magento2_homepro_product_2_v2","node":"TGeJyLN7QhWm3nsFo-bVxA","reason":{"type":"query_shard_exception","reason":"failed to create query: For input string: \"xxx\"","index_uuid":"4Z6fNLOJT9mTqJ6KP9Py2Q","index":"magento2_homepro_product_2_v2","caused_by":{"type":"number_format_exception","reason":"For input string: \"xxx\""}}}]},"status":400}
@krishprakash @engcom-Bravo this was still reproduced on M2.4.0-p1
@krishprakash @engcom-Bravo this was still reproduced on M2.4.0-p1
Try to use my solution https://github.com/betagento/magento2_search_fixing
Still reproduced on Magento 2.4.2-p1
Using https://github.com/betagento/magento2_search_fixing fixed my issue
Reproduced in 2.4.3-p1
As @HarryHung-Shopstack describes, we can search for numbers, but trying to do a search for any string results in the error above (number_format_exception). Haven't tested the fix from @trunglv yet, will edit here with results when tested.
We narrowed down the problematic attribute which was of type int not decimal - so this may affect other number types.
reproduced in 2.4.5-p1 and https://github.com/betagento/magento2_search_fixing dont fix for me.
Magento will ignore any closed issue (and close any new one as quickly as possible) - no point commenting on this one. Raise a new issue and reference this one (see #30194). I've had to raise 4 or 5 issues for a problem before to get it fixed.
https://github.com/betagento/magento2_search_fixing doesn't work any longer for me either in 2.4.5-p1.
my solution is fix in amasty shopby
app/code/Amasty/Shopby/Model/Layer/Filter/Category.php em apply $categoryId = is_numeric($categoryId) ? $categoryId : null;
where $categoryId is not validated and used for atack population log, requests contains ?cat=string and others sql injection
https://github.com/betagento/magento2_search_fixing doesn't work any longer for us either. We are on Magento2.4.4-p2. This error is thrown constantly in our exception.log in Magento2. Also, we do not have Amasty/Shopby module on our store.
I found a bug in the Elasticsearch extension when I tried to use the search functionality.
Here is a log message I got
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: For input string: \"xxx\"","index_uuid":"w5egRGlqQV6LbgrdYBqBYQ","index":"magento2_product_26_v157"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"magento2_product_26_v157","node":"UulsefOgTbiBKXUkTrwSPg","reason":{"type":"query_shard_exception","reason":"failed to create query: For input string: \"kawai\"","index_uuid":"w5egRGlqQV6LbgrdYBqBYQ","index":"magento2_product_26_v157","caused_by":{"type":"number_format_exception","reason":"For input string: \"xxx\""}}}]},"status":400}
What I found is: Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool was missing an item for a double type attribute. So we should add a new one:
<item name="double" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\DoubleTransformer</item>
or<item name="float" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\FloatTransformer</item>
File: vendor/magento/module-elasticsearch/etc/di.xml
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Search functionality should work properly.
Actual result (*)
It doesn't work if there is a product attribute type is a double that is considered in the search query.