gpt4 book ai didi

elasticsearch - .keyword上的聚合仅返回包含特定字符串的键

转载 作者:行者123 更新时间:2023-12-02 23:12:41 25 4
gpt4 key购买 nike

flex 搜索中的聚合新手。使用7.2。我试图在Tree.keyword上写一个聚合,以仅返回包含包含单词“Branch”的键的文档数。我尝试了子聚合,bucket_selector(不适用于键字符串)和脚本。任何人都对如何解决这个问题有任何想法或建议?

对应:

{
"testindex" : {
"mappings" : {
"properties" : {
"Tree" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
}
}
}
}
}

返回所有键但我需要做的示例查询仅限于仅返回具有“Branch”或更好的键,而仅返回有多少“Branch”键的计数:
GET testindex/_search
{
"aggs": {
"bucket": {
"terms": {
"field": "Tree.keyword"
}
}
}
}

返回值:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "testindex",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"Tree" : [
"Car:76",
"Branch:yellow",
"Car:one",
"Branch:blue"
]
}
}
]
},
"aggregations" : {
"bucket" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Car:76",
"doc_count" : 1
},
{
"key" : "Branch:yellow",
"doc_count" : 1
},
{
"key" : "Car:one",
"doc_count" : 1
},
{
"key" : "Branch:blue",
"doc_count" : 1
}
]
}
}
}

最佳答案

您必须添加包含项才能获得极限结果。这是代码示例,希望对您有所帮助。

 GET testindex/_search
{
"_source": {
"includes": [
"Branch"
]
},
"aggs": {
"bucket": {
"terms": {
"field": "Tree.keyword"
}
}
}
}

关于elasticsearch - .keyword上的聚合仅返回包含特定字符串的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531014/

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