gpt4 book ai didi

elasticsearch - 类型的 Elasticsearch 限制结果

转载 作者:行者123 更新时间:2023-11-29 02:53:39 26 4
gpt4 key购买 nike

我有以下查询

$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 个结果,用于自动完成。当我设置过滤器限制时,只有第一种类型的结果会被过滤,对于其他类型,我会得到所有结果。

我该怎么做?

谢谢

最佳答案

{
"aggregations": {
"types": {
"terms": {
"field": "_type"
},
"hits": {
"top_hits": {
"size": 3
}
}
}
}
}

如果您使用的是 ElasticSearch 1.4.0,则可以使用 terms aggregation在“_type”字段上并使用 top hits aggregation作为子聚合并将其大小设置为 3(在您的情况下)。

希望对您有所帮助。

关于elasticsearch - 类型的 Elasticsearch 限制结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13818892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com