W
W
WebDev2016-10-11 14:32:45
elasticsearch
WebDev, 2016-10-11 14:32:45

Elasticsearch grouping and limit?

The index consists of entity_id, type, name fields.
The search is carried out by the name field, but in the search result you need to display 10 results for each type (there are 3 types in total so far).
How can this be configured?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Cheremisin, 2016-10-11
@leahch

It? https://www.elastic.co/guide/en/elasticsearch/refe...

{
"size": 10,
"query": {....}
}

M
MintTea, 2016-10-11
@MintTea

Well, something like this.
Top hits aggregation
Terms aggregation

curl -XGET http://localhost:9200/index/type/_search -d '{
    "query": {
        "match_all": {}
    },
    "aggs": {
        "group_by_types": {
            "terms": {
                "field": "type"
            },
            "aggs": {
                "top_hits_in_group": {
                    "top_hits": {
                        "size": 10
                    }
                }
            }
        }
    }
}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question