I have separated my time-series data into day wise indexes. Let's say I have 2 days indexes.
- 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
}
}
-
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.