If I have a bunch of documents in elaticsearch that I want to be returned grouped by the one field of the document, how do I do it? Also I need it to consistently return a fixed number of results (using set maxresults)
For example if I have a bunch of documents each document representing a person and fields of the document containing attributes of the person. Let's say each person has a city field in the document. I would like to query Elasticsearch in a way that will return 50 results that are grouped by city. By 50 results I want to know how it is possible to return 50 cities mapped to all the people in those cities.
I found an implementation in:
But i want to apply pagination to these results as well. I dont see a setOffset and setLimit possibility in ES. Ideas?
Query you are looking for looks like this:
In Elastica, equivalent query could be created this way:
If you want to paginate results, just change arguments passed into
setFrom
andsetSize
.