具有多个位置的弹性搜索地理距离过滤器 - 可能? [英] ElasticSearch geo distance filter with multiple locations in array - possible?
问题描述
{
name :foobar,
locations:[
{
lat:40.708519,
lon:-74.003212
},
{
lat:39.752609,
lon:-104.998100
},
{
lat:51.506321,
lon -0.127140
}
]
}
根据< a href =http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter/ =noreferrer> ElasticSearch参考指南
geo_distance
过滤器可以与文档的多个位置/点
配合使用。一旦单个位置/点与过滤器匹配,
文档将被包含在过滤器中。
那么,是吗可能创建一个地理距离过滤器来检查数组中的所有位置?
不幸的是,这似乎不起作用:
filter:{
geo_distance:{
distance:100 km,
locations:40,-105
}
}
}
throws QueryParsingException [ myIndex]找不到geo_point字段[locations]
,因为位置
不是一个 geo_point
但是一个 geo_point
s的数组。
你是否指定了 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:{
属性:{
locations:{type:geo_point }
}
}
}'
curl -XPUT'http:// localhost:9200 / twitter / tweet / 1'-d'
{
user:kimchy,
postDate:2009-11-15T13:12:00,
message:尝试弹性搜索那么好?,
位置:[{
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 尝试弹性搜索,到目前为止这么好?,
位置:[{
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
}
}
}
}
}
}'
Let's say we have a bunch of documents in an ElasticSearch index. Each documents has multiple locations in an array, like this:
{
"name": "foobar",
"locations": [
{
"lat": 40.708519,
"lon": -74.003212
},
{
"lat": 39.752609,
"lon": -104.998100
},
{
"lat": 51.506321,
"lon": -0.127140
}
]
}
According to the 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.
So, is it possible to create a geo distance filter which checks all the locations in the array?
This doesn't seem to work, unfortunately:
{
"filter": {
"geo_distance": {
"distance": "100 km",
"locations": "40, -105"
}
}
}
throws "QueryParsingException[[myIndex] failed to find geo_point field [locations]
" since locations
is not a single geo_point
but an array of geo_point
s.
Did you specify a geo_point mapping for your document?
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
}
}
}
}
}
}'
这篇关于具有多个位置的弹性搜索地理距离过滤器 - 可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!