Limit results per document type in Elasticsearch Limit results per document type in Elasticsearch elasticsearch elasticsearch

Limit results per document type in Elasticsearch


I would do it with a terms aggregation on the type meta field and then use a top_hits sub-aggregation, like this:

{  "size": 0,  "aggs": {    "types": {      "terms": {        "field": "_type"      },      "aggs": {        "topten": {          "top_hits": {            "size": 10          }        }      }    }  }}