【问题标题】:Is it possible to search by geo-shape type in Elasticsearch是否可以在 Elasticsearch 中按地理形状类型进行搜索
【发布时间】:2020-03-28 02:53:11
【问题描述】:

我有以下索引映射:

PUT testing/_mapping
{
  "properties": {
    "location": {
      "type": "geo_shape"
    }
  }
}

我索引了两个文档:

PUT testing/_doc/1
{
  "location": {
    "type": "point",
    "coordinates": [13.400544, 52.530286]
  }
}
PUT testing/_doc/2
{
  "location": {
    "type" : "linestring",
    "coordinates" : [[-77.03653, 38.897676], [-77.009051, 38.889939]]
  }
}

现在我想按地理形状类型查找文档,例如只有type=point 的文档(文档 1)。在 Elasticsearch 中可以吗?我尝试了以下搜索,但它总是返回 0 个结果。

GET testing/_search
{
  "query":{
    "bool": {
      "must": [
        {
          "term": {
            "location.type": {
              "value": "point"
            }
          }
        }
      ]
    }
  }
}

我正在使用 Elasticsearch 7.2.1。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您无法通过 location.type 字段进行搜索,它不可搜索。

    我的建议是你也可以在另一个字段中索引你的形状类型,像这样:

    PUT testing/_doc/1
    {
      "location": {
        "type": "point",
        "coordinates": [13.400544, 52.530286]
      },
      "type": "point"
    }
    PUT testing/_doc/2
    {
      "location": {
        "type" : "linestring",
        "coordinates" : [[-77.03653, 38.897676], [-77.009051, 38.889939]]
      },
      "type": "linestring"
    }
    

    然后你可以这样搜索:

    GET testing/_search
    {
      "query":{
        "bool": {
          "must": [
            {
              "term": {
                "type.keyword": "point"
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-15
      • 2011-11-21
      • 2022-01-15
      • 1970-01-01
      • 2016-04-26
      • 2021-11-06
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多