elasticsearch - 在Elasticsearch中是否可以按地理形状类型进行搜索

标签 elasticsearch

我有以下索引映射:

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。

最佳答案

您无法通过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"
          }
        }
      ]
    }
  }
}

关于elasticsearch - 在Elasticsearch中是否可以按地理形状类型进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156781/

相关文章:

Elasticsearch:计算返回错误值

elasticsearch - 具有存在/缺失过滤器的elasticsearch脚本查询

scala - 具有多个连接的 Slick Reactive Streams

java - 在 Elasticsearch 中搜索列数据的最后四位

elasticsearch - 日志存储 : use environment variable

elasticsearch - 正确的语法,用于在Kibana可视化中将过滤器聚合添加为JSON输入(过滤特定属性值)

python-3.x - 如何使用python API获取Elasticsearch集群的运行状况?

elasticsearch - 如何检索原始的 Percolator 查询

elasticsearch - 从日志文件中抽出时间

php - _score,同时在Elasticsearch中进行索引