gpt4 book ai didi

elasticsearch - 带有地理位置的ElasticSearch _Type

转载 作者:行者123 更新时间:2023-12-02 22:26:14 26 4
gpt4 key购买 nike

我设置了一个 flex 搜索索引,其中包含每个国家/地区的不同_type映射。

因此,存在“us”,“au”,“uk”等的映射。

每个映射都包括“geo_point”类型的位置映射

在添加不同的_types之前

我的查询排序如下所示:

"sort" : [
{

"_geo_distance" : {
"postcode.location" : [' . $mylocation_long . ',' . $mylocation_lat . '],
"order" : "asc",
"unit" : "km"
}
}
],

向数据中添加_types并映射它不再起作用,而是将其指定为:
 "sort" : [
{

"_geo_distance" : {
"$country.location" : [' . $mylocation_long . ',' . $mylocation_lat . '],
"order" : "asc",
"unit" : "km"
}
}
],

这很好。

但是,有时需要在单个国家/地区之外进行查询。因此,将其设置为“us.location”是不正确的,并且将无法正常工作。

在这种情况下,当我不知道国家/地区并需要按 map 位置对我进行排序时,该如何进行排序。

还是无法解决这种情况,并且所有文档都必须具有相同的_type才能起作用?

最佳答案

抱歉,如果我缺少明显的内容,但是为什么不能仅对“位置”进行排序。似乎工作正常:

curl -XDELETE localhost:9200/test-idx/ && echo 
curl -XPUT localhost:9200/test-idx/ -d '
{
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings": {
"us": {
"properties": {
"location": {
"type": "geo_point"
}
}
},
"uk": {
"properties": {
"location": {
"type": "geo_point"
}
}
},
"au": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}' && echo
curl -XPUT localhost:9200/test-idx/us/1 -d '
{
"location": "42.3606402,-71.0674569"
}
' && echo
curl -XPUT localhost:9200/test-idx/uk/2 -d '
{
"location": "51.5286416,-0.1017943"
}
' && echo
curl -XPUT localhost:9200/test-idx/au/3 -d '
{
"location": "-33.8471226,151.0594183"
}
' && echo

curl -XPOST localhost:9200/test-idx/_refresh && echo
curl "localhost:9200/test-idx/_search?pretty" -d '{
"query": {
"match_all": {}
},
"sort" : [
{
"_geo_distance" : {
"location" : "52.3712989,4.8937347",
"order" : "asc",
"unit" : "km"
}
}
]
}' && echo

输出:
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"_index":"test-idx","_type":"us","_id":"1","_version":1}
{"ok":true,"_index":"test-idx","_type":"uk","_id":"2","_version":1}
{"ok":true,"_index":"test-idx","_type":"au","_id":"3","_version":1}
{"ok":true,"_shards":{"total":1,"successful":1,"failed":0}}
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : null,
"hits" : [ {
"_index" : "test-idx",
"_type" : "uk",
"_id" : "2",
"_score" : null, "_source" : {"location": "51.5286416,-0.1017943"},
"sort" : [ 355.2735714686373 ]
}, {
"_index" : "test-idx",
"_type" : "us",
"_id" : "1",
"_score" : null, "_source" : {"location": "42.3606402,-71.0674569"},
"sort" : [ 5563.606078215864 ]
}, {
"_index" : "test-idx",
"_type" : "au",
"_id" : "3",
"_score" : null, "_source" : {"location": "-33.8471226,151.0594183"},
"sort" : [ 16650.926847312003 ]
} ]
}
}

关于elasticsearch - 带有地理位置的ElasticSearch _Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18071196/

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