首页 > 解决方案 > Elasticsearch geo_shape 点搜索返回错误的geometrycollection 文档

问题描述

弹性搜索版本:6.5.0

我对 geo_shape 点搜索有疑问,它看起来很简单,但我不明白为什么..我会很感激任何想法..

我的索引架构映射:

{
    "fullname": {
        "type": "text"
    },
    "location": {
      "type": "geo_shape"
    }
}

我创建了包含三个 5 公里圆圈的文档。(阿根廷、印度和伦敦)

PUT /location_test/region/doc123456
{
  "fullname": "Argentina, India and London",
  "location": {
    "geometries": [

    {
        "coordinates": [
          -58.4358666,
          -34.5884887
        ],
        "type": "circle",
        "radius": "5.0km"
      },

      {
        "coordinates": [
          72.8457919,
          19.1045692
        ],
        "type": "circle",
        "radius": "5.0km"
      },
      {
        "coordinates": [
          -0.1436263,
          51.5412567
        ],
        "type": "circle",
        "radius": "5.0km"
      }
    ],
    "type": "geometrycollection"
  }
}

当我使用以下查询搜索南安普敦的一个点(lat=50.909594,long=-1.404098)时:

GET location_test/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "point",
          "coordinates": [
            -1.404098,
            50.909594
          ]
        }
      }
    }
  }
}

但是我拿回了文档 doc123456,这没有任何意义,因为阿根廷、印度和伦敦离南安普顿很远。它不应与查询匹配,并且不应返回任何结果。

有趣的是,然后我更新了上面的文档,(删除了一个圆圈,阿根廷),现在,该文档只包含印度和伦敦圈子。

运行相同的查询,我没有得到结果,这是正确的。

为什么包含这三个圆圈的文档有错误的结果?

我是否正确使用了正确的映射和字段类型“geometrycollection”?

任何建议表示赞赏。

非常感谢您。

标签: elasticsearchelasticsearch-query

解决方案


无法使用 6.6.0 复制此内容:

PUT location_test
{"mappings":{"region":{"properties":{"fullname":{"type":"text"},"location":{"type":"geo_shape","strategy":"recursive"}}}}}

POST /location_test/region/doc123456
{"fullname":"Argentina, India and London","location":{"geometries":[{"coordinates":[-58.4358666,-34.5884887],"type":"circle","radius":"5.0km"},{"coordinates":[72.8457919,19.1045692],"type":"circle","radius":"5.0km"},{"coordinates":[-0.1436263,51.5412567],"type":"circle","radius":"5.0km"}],"type":"geometrycollection"}}

GET location_test/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "point",
          "coordinates": [
            -1.404098,
            50.909594
          ]
        }
      }
    }
  }
}

0 次点击——人们所期望的。


尝试运行GET location_test/_search?explain=true并分享响应。


推荐阅读