magento2: Elasticsearch issue "number_format_exception" - 2.4.1

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

<type name="Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool">
        <arguments>
            <argument name="valueTransformers" xsi:type="array">
                <item name="default" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer</item>
                <item name="date" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\DateTransformer</item>
                <item name="float" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\FloatTransformer</item>
                <item name="integer" xsi:type="object">Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\IntegerTransformer</item>
            </argument>
        </arguments>
    </type> 

Preconditions (*)

  1. Magento 2.4.1
  2. Elastic Search

Steps to reproduce (*)

  1. Try to search for a product on the frontend
  2. It doesn’t work if there is a product attribute type is a double that is considered in the search query.

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (4 by maintainers)

Most upvoted comments

Still reproduced on Magento 2.4.2-p1

Using https://github.com/betagento/magento2_search_fixing fixed my issue

Hello @trunglv. Feel free to reopen/comment once you confirm that issue reproduce on 2.4-develop instance Thanks!!