Elastic search advanced query for showing price changes on time series indexes

I have separated my time-series data into day wise indexes. Let's say I have 2 days indexes.

  1. index1 data-timeseries-14-04-2019 :

example data:

{{"_id": 1,
  "product_name": "mobile1",
  "product_id": "12145",
  "created_at": "2014-04-14",
  "offer_price": 89
  },
 {"_id": 2,
  "product_name": "mobile2",
  "product_id": "12146",
  "created_at": "2014-04-14",
  "offer_price": 70
  }
 }
  1. index2 data-timeseries-15-04-2019 :

     {{"_id": 1,
       "product_name": "mobile2",
       "product_id": "12146",
       "created_at": "2014-04-15",
       "offer_price": 80
       },
      {"_id": 2,
       "product_name": "mobile1",
       "product_id": "12145",
       "created_at": "2014-04-15",
       "offer_price": 89
       }
      }
    

Here unique products are identified by their "product_id"

I want to write a query showing number of products, those have changed their offer_price.

please help me out.

I tried something like this

{
    "aggs": {
        "distinct_by_product_id": {
            "terms": {
                "field": "product_id.keyword",
                "min_doc_count": 2,
                "size": 10

            },
            "aggs": {"count_distinct_prices":
                {"cardinality": {
                    "field": "offer_price"
                }}
            }
        }}

}

`

First applying term aggregation on product_id and then finding the distinct no offer_price. if the distinct no is larger than 1, that product is counted as price variant product.

  • But as I am using term aggregation, for large no of data I can't get all products data.

You can wrap your terms aggregation in a composite aggregation. The composite aggregation allows you to paginate through all buckets.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.