【问题标题】:Elasticsearch geo_shape point-search returns the wrong geometrycollection documentsElasticsearch geo_shape 点搜索返回错误的geometrycollection 文档
【发布时间】:2020-08-04 21:22:48
【问题描述】:

Elasticsearch 版本: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”?

欢迎提出任何建议。

非常感谢。

【问题讨论】:

    标签: elasticsearch elasticsearch-query


    【解决方案1】:

    无法使用 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 并分享响应。

    【讨论】:

    • 感谢您的回复。这里是 _explanation 部分:` "_explanation": { "value": 1, "description": "ConstantScore(IntersectsPrefixTreeQuery(fieldName=location,queryShape=Pt(x=-1.404098,y=50.909594),detailLevel=9, prefixGridScanLevel=8))", "details": [] } ` 也许我也应该尝试更新版本。谢谢
    • 您目前使用的是哪个版本?也许这真的是一个已经修复的错误。
    • Elasticsearch 版本:6.5.0
    • 我安装了elasticsearch 6.6.0,当我创建映射时,遇到了这个“不支持圆形几何”的问题,找到了解决方案(discuss.elastic.co/t/circle-geometry-is-not-supported/171093),添加“策略”:“递归" 在 geo_shape 映射中。 "location": { "type": "geo_shape", "strategy" : "recursive" } 然后运行相同的查询,它起作用了。它返回0结果,对于上面的查询,这是正确的。看起来 6.6.0 版解决了这个问题。
    • 对不起,jzzfs,你是对的,你提供的答案已经有“策略”:“递归”,我忽略了它。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多