Elastic search results for types

I have the following query

$queryDefinition = [ 'query' => [ 'bool' => [ 'must' => [ [ 'query_string' => [ 'default_field' => '_all', 'query' => $term ] ] ], 'must_not' => [], 'should' => [] ], ], //'filter' => [ // 'limit' => ['value' => 3], //], 'from' => 0, 'size' => 50, 'sort' => [], 'facets' => [ 'types' => [ 'terms' => ['field' => '_type'] ] ] ]; 

in the index we have 5 types, and I would like to show only 3 results from each type, for autocomplete. when I set a filter restriction, only the results from the first type are filtered, for other types I get all the results.

How can i do this?

thanks

+4
source share
1 answer
 { "aggregations": { "types": { "terms": { "field": "_type" }, "hits": { "top_hits": { "size": 3 } } } } } 

If you use ElasticSearch 1.4.0, you can use the aggregation of terms in the "_type" field and use top hits aggregation as a sub-aggregation and set its size to 3 (in your case).

Hope this helps.

0
source

All Articles