Hi All,
I think I've figured it out:
"filter": {
"and": {
"or": [
{
"nested": {
"path": "variants",
"filter": {
"range": { "price": { "gt":10,"lte":20}}
}
}
}
]
}
It will be a lot of code as nested within the last node, but I think it
will work.
Dev
On Friday, January 9, 2015 at 3:22:09 PM UTC, Dev Day wrote:
>
> 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:
>
> 1) 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
> 2) 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/0771a418-83a7-4e7a-9ccb-9faf76c60ade%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.