Hi All,
Please see a working example of a document.
The document has variants as a nested document within each root document.
The data has 3 records as can be seen below.
I would like to do the following:
- For the filter aggregation for colour, I would like to filter by two
ranges, in a OR condition - gt 10 lte 20 and gt 30 and lte 40 - For the same filter aggregation for colour, I would like to filter by
the above AND size = small.
Can anyone help?
I cannot seem to use AND / OR or BOOL logic with nested / non-nested
combinations?
DELETE /testindex/
PUT /testindex/
{
"mappings": {
"products":{
"properties": {
"variants":{
"type":"nested"
}
}
}
}
}
POST /_bulk
{"create":{"_index":"testindex","_type":"products","_id":"1"}}
{"code":"1", "variants": [{"sku":"123", "price": 15}], "colour":"blue",
"size":"small"}
{"create":{"_index":"testindex","_type":"products","_id":"2"}}
{"code":"2", "variants": [{"sku":"456", "price": 30}], "colour":"red",
"size":"small"}
{"create":{"_index":"testindex","_type":"products","_id":"3"}}
{"code":"3", "variants": [{"sku":"789", "price": 35}], "colour":"red",
"size":"large"}
POST /testindex/products/_search
{
"aggs": {
"colour":{
"filter":{
"nested": {
"path": "variants",
"filter": {
"range": { "price": { "gt":10,"lte":20}}
}
}
},
"aggs":{
"colour":{
"terms":{ "field": "colour" }
}
}
},
"price":{
"nested": {
"path":"variants"
},
"aggs":{
"price":{
"terms":{ "field": "price" }
}
}
}
},
"post_filter" : {
"nested": {
"path":"variants",
"filter": {
"range": { "price": { "gte":20}}
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5c37741e-d559-4d6f-b7f3-58c648b33930%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.