gpt4 book ai didi

elasticsearch - Elasticsearch聚合不起作用

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

我有页面访问日志的索引。每个访问页面的用户都用以下行记录:

{
"_index": "logs",
"_type": "visit",
"_id": "AVco3MoAdMBqjXxJcqfF",
"_version": 1,
"_score": 1,
"_source": {
"@version": "1",
"@timestamp": "2016-09-14T13:22:20.074Z",
"user": "309424",
"page": "15399",
"countryCode": "FR"
}
}

我正在尝试通过countryCode获得访问量最高的页面

日志/访问/ _search?search_type = count上的POST请求:
 {  
"aggs":{
"pages":{
"terms":{
"field":"page"
}
}
},
"query":{
"bool":{
"must":[
{
"term":{
"countryCode":{
"value":"FR",
"boost":1
}
}
}
]
}
}
}

但是响应数组“buckets”为空。而当我使用“用户”而不是“countryCode”进行查询时,我在指定的用户浏览最多的页面上获得了良好的结果。但是我需要按国家。

countryCode字段和user字段之间有什么区别?两者都声明为字符串
"countryCode": {
"type": "string"
},
"user": {
"type": "string"
}

最佳答案

您的countryCode字段是经过分析的字符串,因此您的查询需要像这样

{  
"aggs":{
"pages":{
"terms":{
"field":"page"
}
}
},
"query":{
"bool":{
"must":[
{
"term":{
"countryCode":{
"value":"fr", <--- lowercase fr here
"boost":1
}
}
}
]
}
}
}

或者您可以保留大写的 FR并使用 match查询代替
{  
"aggs":{
"pages":{
"terms":{
"field":"page"
}
}
},
"query":{
"bool":{
"must":[
{
"match":{ <--- use match
"countryCode":{
"value":"FR",
"boost":1
}
}
}
]
}
}
}

关于elasticsearch - Elasticsearch聚合不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39491883/

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