弹性搜索限制结果类型 [英] elastic search limit results for types
本文介绍了弹性搜索限制结果类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询
$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']
]
]
];
在索引中我们有5种类型,我想只显示每个类型的3个结果,用于自动完成当我设置过滤器限制时,只有第一个类型的结果被过滤,对于其他类型,我得到所有的结果。
in the index we have 5 types, and i would like to show only 3 results from each type, for autocomplete. when i set the filter limit only the results from the first type are filtered, for other types i get all the results.
我该怎么办?
谢谢
推荐答案
{
"aggregations": {
"types": {
"terms": {
"field": "_type"
},
"hits": {
"top_hits": {
"size": 3
}
}
}
}
}
如果您使用ElasticSearch 1.4.0,可以使用术语聚合,并使用热门聚合作为子聚合并设置它大小为3(在您的情况下)。
If you're using ElasticSearch 1.4.0, you can use terms aggregation on "_type" field and use top hits aggregation as sub aggregation and set its size to 3 (in your case).
希望有所帮助。
这篇关于弹性搜索限制结果类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文