ElasticSearch - Nested Filtered Aggregations -
i'm looking way min , max value 2 level nested object have been filtered. below im trying min , max price has currencycode
gbp. each product can have multiple skus , each sku can have multiple prices (though 1 gbp):
"hits": [ { "_index": "product", "_type": "main", "_id": "1", "_score": 1, "_source": { "skus": [ { "prices": [ { "currencycode": "gbp", "price": 15 } ] } ] } },{ "_index": "product", "_type": "main", "_id": "2", "_score": 1, "_source": { "skus": [ { "prices": [ { "currencycode": "gbp", "price": 20 } ] } ] } }, { "_index": "product", "_type": "main", "_id": "3", "_score": 1, "_source": { "skus": [ { "prices": [ { "currencycode": "gbp", "price": 25 } ] } ] } }] }
so want min 15, max 25. i've looked filter aggregation , nested aggregation can not come answer.
i'm using elasticsearch version 5.5.
i'm trying query working correctly first before converting nest .net.
any appreciated.
you can nest "nested" , "filter" aggregations, this:
{ "size": 0, "aggs": { "skus": { "nested": { "path": "skus" }, "aggs": { "prices": { "nested": { "path": "skus.prices" }, "aggs": { "gbp_filter": { "filter": { "term": { "skus.prices.currencycode": "gbp" } }, "aggs": { "min_price": { "min": { "field": "skus.prices.price" } }, "max_price": { "max": { "field": "skus.prices.price" } } } } } } } } } }
however, since 1 price can gbp, true every sku, there can 1 price per currency? if that's case, suggest not use nested data type prices here. instead can use mapping this:
{ "product": { "properties": { "skus": { "type": "nested", "properties": { "prices": { "properties": { "gbp": {"properties": {"price": {"type": "integer"}}}, "usd": {"properties": {"price": {"type": "integer"}}}, ...remaining currencies... } } } } } } }
the mapping not concise, more efficient query, , queries nicer. (almost) anytime can denormalize data rid of nesting, if have duplicate information (in order meet needs of different types of queries), it's idea.
wiki
Comments
Post a Comment