5

I am trying to perform multiple aggregations at the same level with ElasticSearch using the elasticsearch-rails and elasticsearch-model gems.

In the query hash that I am generating, I have the following -

    def query_hash(params, current_person = nil, manager_id = nil)
      aggs = {}
      aggs[:home_country_id] = {terms: {field: "home_country_id"}}
      aggs[:home_region_id] = {terms: {field: "home_region_id"}}
      {
        sort: [ { created_at: { order: "desc" } }, id: { order: "desc" } ],
        aggs: aggs
      }
    end

The response I stored in an object es_response.

When I search for both the aggregations, I can only find the last one in the response.

es_response.response["aggregrations"] only has the response of the latest aggregation object, home_region_id.

I couldn't find much documentation on the ES Reference on structuring multiple aggregations on the same level although there was a lot about nesting aggregations.

How can I fix this?

My ES version is 5.1

Michael Victor
  • 861
  • 2
  • 18
  • 42

0 Answers0