gpt4 book ai didi

在数组中具有多个位置的 ElasticSearch 地理距离过滤器 - 可能吗?

转载 作者:行者123 更新时间:2023-11-29 02:43:42 25 4
gpt4 key购买 nike

假设我们在 ElasticSearch 索引中有一堆文档。每个文档都有多个位置在一个数组中,像这样:

{
"name": "foobar",
"locations": [
{
"lat": 40.708519,
"lon": -74.003212
},
{
"lat": 39.752609,
"lon": -104.998100
},
{
"lat": 51.506321,
"lon": -0.127140
}
]
}

根据ElasticSearch reference guide

the geo_distance filter can work with multiple locations / points per document. Once a single location / point matches the filter, the document will be included in the filter.

那么,是否可以创建一个地理距离过滤器来检查数组中的所有位置?

不幸的是,这似乎不起作用:

{
"filter": {
"geo_distance": {
"distance": "100 km",
"locations": "40, -105"
}
}
}

抛出“QueryParsingException[[myIndex] 未能找到 geo_point 字段 [locations]”,因为 locations 不是单个 geo_point 而是一个数组geo_point 的。

最佳答案

您是否指定了 geo_point mapping为您的文档?

curl -XDELETE 'http://localhost:9200/twitter/'
curl -XPUT 'http://localhost:9200/twitter/'

curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
"tweet" : {
"properties" : {
"locations" : {"type" : "geo_point"}
}
}
}'

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elastic Search, so far so good?",
"locations" : [{
"lat" : 50.00,
"lon" : 10.00
},
{
"lat" : 40.00,
"lon" : 9.00
}]
}'

curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elastic Search, so far so good?",
"locations" : [{
"lat" : 30.00,
"lon" : 8.00
},
{
"lat" : 20.00,
"lon" : 7.00
}]
}'

curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "20km",
"tweet.locations" : {
"lat" : 40.00,
"lon" : 9.00
}
}
}
}
}
}'

关于在数组中具有多个位置的 ElasticSearch 地理距离过滤器 - 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16113439/

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