gpt4 book ai didi

elasticsearch - elasticsearch过滤器不适用于聚合

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

我正在与elasticsearch一起使用,并创建以下映射,创建地理索引,用于对其进行比较的长字段(gte),以及用于识别性别的 bool(boolean) 值归档。

curl -XDELETE 'http://localhost:9165/locations' && echo
curl -XPUT 'http://localhost:9165/locations' && echo
curl -XPUT 'http://localhost:9165/locations/location/_mapping' -d '
{
"location": {
"properties": {
"location": {"type" : "geo_point"},
"gender" : {"type" : "boolean"},
"last_appearance": {"type": "long"}
}
}
}' && echo "Mapping done"

然后我正在执行以下插入操作以建立索引:
curl -XPUT 'http://localhost:9165/locations/location/1' -d '{
"location":
{
"lat": "47.785346",
"lon": "67.701857"
},
"category_id": "5",
"gender": "true",
"city": "Almaty",
"last_appearance": "3333333",
"venue_id": "5229774711d2a3ec9e333d00"
}'

最后,我尝试过滤所有数据,其中用户的最后一次出现是较大的,然后是一些测试值,在我的情况下是222222222222222222,城市是阿拉木图,然后我想对过滤后的数据进行一些汇总。
curl -X GET http://localhost:9165/locations/location/_search -d '
{
"filter" : {
"and" : [
{
"range" :
{
"last_appearance" :
{
"gte" : "222222222222222222"
}
}
},
{
"term" : {"city" : "Almaty"}
}
]
},

"aggs" : {
"venues" : {
"terms" : { "field" : "venue_id"},
"aggs": {
"genders" : {
"terms" : {"field" : "gender"}
}
}
}
}
}' | python -mjson.tool

在这种情况下,我不想聚合任何内容,因为333333小于2222222222222222222,但是Elastic开始聚合:
{
"_shards": {
"failed": 0,
"successful": 1,
"total": 1
},
"aggregations": {
"venues": {
"buckets": [
{
"doc_count": 1,
"genders": {
"buckets": [
{
"doc_count": 1,
"key": "true"
}
]
},
"key": "5229774711d2a3ec9e333d00"
}
]
}
},
"hits": {
"hits": [],
"max_score": null,
"total": 0
},
"timed_out": false,
"took": 1
}

请帮我处理一下。感谢您阅读这个冗长的问题。

最佳答案

感谢@nKandel的评论,它真的很有帮助。

最终查询如下:

curl -X GET http://localhost:9165/locations/location/_search -d '
{
"size" : 0,
"aggregations" : {
"cities" : {
"filter" : {
"term" : {
"city": "Almaty"
}
},
"aggregations": {
"lasts" : {
"filter" : {
"range" : {
"last_appearance" : {
"gte" : 100
}
}
},
"aggregations": {
"venues" : {
"terms" : { "field" : "venue_id"},
"aggregations": {
"genders" : {
"terms" : {"field" : "gender"}
}
}
}
}
}
}
}
}
}
'| python -mjson.tool

关于elasticsearch - elasticsearch过滤器不适用于聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734765/

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