Reputation: 579
Does Elasticsearch have a mechanism to query for documents while limiting that only a number of those documents match a separate condition?
I have a collection of documents that have a field indicating a category. Is it possible to query for 100 documents that matches some criteria, while limiting that no more than 20 of those documents have category=A? A similar scenario would be to query for 100 documents while specifying that 20 documents must be of category=A, 30 of category=B and 50 of category C.
Upvotes: 2
Views: 1930
Reputation: 9099
There is no way to get different number of documents per category in a single query .Using msearch You can execute several searches within single api request
GET index85/_msearch
{}
{"query" : {"term" : { "category.keyword": "Political"}},"from":0,"size":15}
{}
{"query" : {"term" : { "category.keyword": "Sports"}},"from":0,"size":5}
Upvotes: 1