1

I have an index with multiple types like below :

  • songs
  • books
  • movies

I am building an API for suggesting indexed items grouped by their type, The problem is that I want a size functionality inside each aggregation, Just like the completion suggester approach which returns an exact number of items for each type. I ended up with multi index query approach to query each type separately, Is there any better approach to handle this ?

Lee H
  • 5,147
  • 4
  • 19
  • 22
Reza Shadman
  • 617
  • 6
  • 15

1 Answers1

1

Each aggregation you specify can have a filter associated with it, so you could reduce the context of an aggregation to a specific type that way. Additionally, you can use the filters aggregation to create buckets for each filter, and run an aggregation with a certain size on each sub-bucket, like this:

GET /_search { "aggs": { "alltypes": { "filters": { "filters": { "songs": {"term": {"_type": "songs"}}, "books": {"term": {"_type": "books"}}, "movies": {"term": {"_type": "movies"}} } }, "aggs": { ... your aggregation for each individual type here ... } } } }

More info about the filters aggregation can be found at http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html

Hopefully that helps, let me know if I misunderstood your question (it was a little uncertain whether you were talking about suggestors or aggregations since both were mentioned in the question).

Lee H
  • 5,147
  • 4
  • 19
  • 22