我的字段映射为geo-shape。
我想给出西北和东南的坐标,并查找其中的区域。
我知道有一个example。所以我复制了这个。
curl -X GET "localhost:9200/example/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
'
这是我的卷曲要求。
curl -X GET "https://atlas-search.company.com/regions_19090403/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"boundaries": {
"shape": {
"type": "envelope",
"coordinates" : [[37.54069137885601, 127.0164930082651], [37.472603386664225, 127.03280083907562]]
},
"relation": "within"
}
}
}
}
}
}
'
但返回
'
{
"error" : {
"root_cause" : [
{
"type" : "invalid_shape_exception",
"reason" : "invalid_shape_exception: Y values [127.03280083907562 to 127.0164930082651] not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "regions_19090403",
"node" : "4ySStuelRfuJrcg_BQvy_Q",
"reason" : {
"type" : "query_shard_exception",
"reason" : "failed to create query: {\n \"bool\" : {\n \"must\" : [\n {\n \"match_all\" : {\n \"boost\" : 1.0\n }\n }\n ],\n \"filter\" : [\n {\n \"geo_shape\" : {\n \"boundaries\" : {\n \"shape\" : {\n \"type\" : \"envelope\",\n \"coordinates\" : [\n [\n 37.54069137885601,\n 127.0164930082651\n ],\n [\n 37.472603386664225,\n 127.03280083907562\n ]\n ]\n },\n \"relation\" : \"within\"\n },\n \"ignore_unmapped\" : false,\n \"boost\" : 1.0\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}",
"index_uuid" : "BFdVr06-TEaSLyaeETsxFQ",
"index" : "regions_19090403",
"caused_by" : {
"type" : "invalid_shape_exception",
"reason" : "invalid_shape_exception: Y values [127.03280083907562 to 127.0164930082651] not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)"
}
}
}
],
"caused_by" : {
"type" : "invalid_shape_exception",
"reason" : "invalid_shape_exception: Y values [127.03280083907562 to 127.0164930082651] not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)"
}
},
"status" : 400
}
,我找不到这个。 我什么都不知道,所以我无法获取有关这种情况的信息。如果您知道这种情况,请分享您的知识。
答案 0 :(得分:2)
对于所有类型,内部类型和坐标字段都是必需的。
在GeoJSON和WKT中,因此在Elasticsearch中,正确的坐标顺序是坐标数组中的经度,纬度(X,Y)。这不同于许多通常使用口语经度(Y,X)的地理空间API(例如Google Maps)。 https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#_envelope
信封编辑 Elasticsearch支持信封类型,该信封类型由形状的左上角和右下角的坐标组成,以[[minLon,maxLat],[maxLon,minLat]]格式表示边界矩形
https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#_envelope
我也认为不回答就给问题打分是不礼貌的。这无助于提高这个社区的质量。
这里更改了我的请求。
{
"query":{
"bool":{
"must":{
"term":{
"isAOI":"true"
}
},
"filter":{
"geo_shape":{
"boundaries":{
"shape": {
"type": "envelope",
"coordinates" : [[126.9243621826172, 37.580228767905275],[127.10941314697267, 37.44406286652748]]
},
"relation": "within"
}
}
},
"should":[
{
"match_all":{
}
}
],
"minimum_should_match":1
}
},
"_source":{
"excludes":[
"polygons",
"boundaries"
]
},
"from":0,
"sort":[
{
"admin_level":"asc"
}
]
}