0

I don't have much idea about Elastic search. Can we compare two types of prices while fetching record from Elastic server. Here's the example

"hits": [
        {
            "_index": "magento2_default_catalog_product_20210531_051304",
            "_type": "_doc",
            "_id": "57",
            "_score": 1.0,
            "_source": {
                "entity_id": "57",
                "visibility": "4",
                "price": [
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 0,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 1,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 2,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 3,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    }
                ]
                "stock": {
                    "is_in_stock": true,
                    "qty": 0
                }
            }
        },
        {
            "_index": "magento2_default_catalog_product_20210531_051304",
            "_type": "_doc",
            "_id": "91",
            "_score": 1.0,
            "_source": {
                "entity_id": "91",
                "visibility": "4",
                "price": [
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 0,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 1,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 2,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    },
                    {
                        "price": 1.0,
                        "original_price": 1.0,
                        "is_discount": false,
                        "customer_group_id": 3,
                        "tax_class_id": 2,
                        "final_price": 0.0,
                        "min_price": 1.0,
                        "max_price": 1.0
                    }
                ],
                "stock": {
                    "is_in_stock": true,
                    "qty": 0
                }
            }
        },
      ]

I have tons of records, now I need those records which have final_price lesser then price. Since price is an array type, I have customer group id and tax class id so I need to compare it with respective index. let's say I have customer group id as 0 and tax class id as 2 so it should compare price and final price from first index or matching index of price.

Appreciate if anybody can help here.

Ramkishan Suthar
  • 403
  • 1
  • 7
  • 26

1 Answers1

0

To be able to query Array inner object you should map your price as a Nested type, arrays of objects do not work as you would expect because you cannot query each object independently of the other objects in the array. If you need to be able to do this then you should use the nested data type instead of the object data type. you can find the solution here. Also you can check ES official documentation about array and nested objects here.

Kaveh
  • 1,158
  • 6
  • 16