gpt4 book ai didi

python-3.x - Elasticsearch聚合给我2个结果,而不是一个结果

转载 作者:行者123 更新时间:2023-12-03 01:42:11 25 4
gpt4 key购买 nike

我想汇总品牌 Realm ,给我两个结果,而不是一个

brands_aggs从这段文字中给了我

{名称:“品牌1”}

2结果
Brand1
但是为什么我只需要Brand 1
将(品牌1)和(品牌1)一词分开

并给了我2个结果

我要汇总的映射

 mapping = {  
"mappings": {

"product": {
"properties": {

"categories": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"fielddata": True
}

"brand": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"fielddata": True
}

}
}
}
}

我的要求
{
"query" : {
"bool": {
"must": [
{"match": { "categories": "AV8KW5Wi31qHZdVeXG4G" }}
]
}
},
"size" : 0,
"aggs" : {
"brand_aggs" : {
"terms" : { "field" : "brand" }
},
"categories_aggs" : {
"terms" : { "field" : "categories" }
}
}

}

来自服务器的响应
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": []
},
"aggregations": {

"categories_aggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "av8kw5wi31qhzdvexg4g",
"doc_count": 1
},
{
"key": "av8kw61c31qhzdvexg4h",
"doc_count": 1
},
{
"key": "av8kxtch31qhzdvexg4a",
"doc_count": 1
}
]
},

"brand_aggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "1", <==== I dont need this , why is give me that ??
"doc_count": 1
},
{
"key": "brand",
"doc_count": 1
}
]
},

}
}

最佳答案

映射具有属性字段,当您要为同一字段具有多个分析器时使用。在您的情况下,您字段的有效名称是“brand.keyword”。当您仅针对“品牌”调用汇总时,它将使用为字符串定义的默认映射。

因此,您的查询应为:

{
"query" : {
"bool": {
"must": [
{"match": { "categories": "AV8KW5Wi31qHZdVeXG4G" }}
]
}
},
"size" : 0,
"aggs" : {
"brand_aggs" : {
"terms" : { "field" : "brand.keyword" }
},
"categories_aggs" : {
"terms" : { "field" : "categories.keyword" }
}
}

}

例如,当您想要搜索与多个分析器相同的属性时,“属性”字段很有用,例如:
         "full_name": {
"type": "text",
"analyzer": "standard",
"boost": 1,
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "ngram_analyzer"
},
"standard":{
"type": "text",
"analyzer": "standard"
}
}
},

关于python-3.x - Elasticsearch聚合给我2个结果,而不是一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46689395/

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