Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price declared as 'double', but indexed as string #1861

Closed
killoff opened this issue Jun 24, 2020 · 2 comments
Closed

Price declared as 'double', but indexed as string #1861

killoff opened this issue Jun 24, 2020 · 2 comments
Assignees
Labels

Comments

@killoff
Copy link

killoff commented Jun 24, 2020

Preconditions

No modification made to the module, no extensions that impact Elasticsuite functionality installed.

Magento Version : 2.3.4

ElasticSuite Version : 6.8.8

Environment : Magento in default mode, Ubuntu

Steps to reproduce

bin/magento indexer:reindex

Expected result

Nested property price.price (.original_price, .final_price etc.) should have float values

		"price": [
			{
				"price": 45.5,
				"original_price": 45.5,
				"is_discount": false,
				"customer_group_id": 0,
				"tax_class_id": 0,
				"final_price": 45.5,
				"min_price": 45.5,
				"max_price": 45.5
			},

Actual result

Nested property price.price (.original_price, .final_price etc.) have string values

		"price": [
			{
				"price": "45.500000",
				"original_price": "45.500000",
				"is_discount": false,
				"customer_group_id": 0,
				"tax_class_id": 0,
				"final_price": "45.500000",
				"min_price": "45.500000",
				"max_price": "45.500000"
			},

As the result, range filter and aggregation on price give unpredictable results.

POST /index_name/_search

{
    "size": 0,
    "aggs": {
        "price": {
            "nested": {
                "path": "price"
            },
            "aggs": {
                "price": {
                    "range": {
                        "field": "price.price",
                        "ranges": [
                            {
                                "to": 10
                            },
                            {
                                "from": 10,
                                "to": 20
                            },
                            {
                                "from": 20,
                                "to": 30
                            }
                        ]
                    }
                }
            }
        }
    }
}

If I add this

$indexData[$rowId]['price'][0]['price'] = (float)$indexData[$rowId]['price'][0]['price'];

Everything works as expected.

It seems that Elasticsuite does not perform types-casting on the data being saved to elasticsearch index.

@androshchuk androshchuk self-assigned this Jun 25, 2020
@androshchuk
Copy link
Contributor

Hello @killoff

I agree that the price format does not correspond to the declared type.
It seems that the situation is the same in clear magento2.

I couldn't find "unpredictable results".
Could you tell me how to reproduce them and also check please, does my PR fix the problem?

Regards

@killoff
Copy link
Author

killoff commented Jun 30, 2020

Hi @androshchuk

Could you tell me how to reproduce them and also check please, does my PR fix the problem?

Thank you for the fix. It DOES fix the issue.
However, I wouldn't use round(), just type casting to float instead 'original_price' => (float)$originalPrice
Or at least round with the higher precision: 'original_price' => round($originalPrice, 5)

I couldn't find "unpredictable results".

I gave an example with aggregation (aggs)
I don't know whether elasticsuite supports price range filter.
The thing is, we don't use all frontend features, only indexers. But we have our custom storefront that operates with es data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants