Multiple filters on Filter Aggregation

Hey,

Using ElasticSearch aggregation to aggregate data on my documents.
so the aggregation request looks something like this

 {  
   "query":{  
      "bool":{  
         "filter":[  
            {  
               "terms":{  
                  "status":[  
                     "active",
                     "deleted"
                  ]
               }
            },
            {  
               "terms":{  
                  "address_ids":[  
                     4078,
                     4080
                  ]
               }
            }
         ]
      }
   },
   "aggregations":{  
      "neighbourhoods":{  
         "terms":{  
            "field":"neighbourhoods",
            "size":100
         }
      },
      "budgets_stats":{  
         "filter":{  
            "range":{  
               "budget":{  
                  "lt":100000
               }
            }
         },
         "aggregations":{  
            "budget":{  
               "stats":{  
                  "field":"budget"
               }
            }
         }
      }
   }
}

i want to filter out documents that match ** budget lower than 100000 ** and add more filters to that specific aggregation.
I cant add it to the query clause, because i have other aggregation in which i dont want these budget filters to apply.

I cant use the filters aggregation either because it creates a different bucket for each filter - instead of 1 bucket with all filters applied to it.

How can create a filter aggregation with more than 1 filter? lets say the other condition should be
"budgets_stats":{
"filter":
{
"range":{
"vip_budget":{
"gt":500
}
}
}
}

i have tried using Array but its not working.

filter: [{:range=>{:budget=>{:lt=>100000}}}, {:range=>{:vip_budget=>{:gt=>500}}}]

getting this error (using rails gems)

Elasticsearch::Transport::Transport::Errors::BadRequest Exception: [400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"Expected [START_OBJECT] under [filter], but got a [START_ARRAY] in [budgets_stats]","line":1,"col":233}],"type":"parsing_exception","reason":"Expected [START_OBJECT] under [filter], but got a [START_ARRAY] in [budgets_stats]","line":1,"col":233},"status":400}

Is this even possible? couldn't find a reference in the documentation of elastic / rails gems for elastic

Will appreciate any help,

Thanks

You can combine filter criteria using the bool tag, much like you can query clauses.

can you show me how the query should look like?

Here's the bool docs

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