【问题标题】:Elastic search 5.3 - failed to find geo_point field弹性搜索 5.3 - 找不到 geo_point 字段
【发布时间】:2018-08-08 08:41:54
【问题描述】:

我指的是弹性搜索文档中给出的Geo Distance Query 示例。

版本:5.3

按照教程,我执行此查询以在索引中插入数据

PUT /my_locations/location/1
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

然后我只是尝试应用也在文档中显示的地理距离查询。

GET /my_locations/location/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "200km",
                    "pin.location" : {
                        "lat" : 40,
                        "lon" : -70
                    }
                }
            }
        }
    }
}

但它向我显示了这个错误。 “未能找到 geo_point 字段 [pin.location]” 其他时候它告诉我这个错误 “字段 [pin.location] 不是 geo_point 字段”。

我需要以不同的方式插入这条记录还是我在查询中遗漏了一些参数?

【问题讨论】:

  • 你能发布你的索引映射吗?您必须在映射中的字段上指定 geo_point 类型(=> elastic.co/guide/en/elasticsearch/reference/current/…
  • 我查看了索引模式,它显示位置的数据类型是数字
  • {"gym":{"mappings":{"gyms":{"properties":{"location":{"type":"float"},"name":{"type ":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"pin":{"properties":{"location":{"properties ":{"lat":{"type":"float"},"lon":{"type":"float"}}}}}}}}}}

标签: javascript elasticsearch kibana elasticsearch-5 kibana-5


【解决方案1】:

谢谢@Pierre Mallet

我查看了文档并得出结论,我首先需要使用 geo_point 数据类型创建索引。我无法在现有索引上应用数据类型。所以我的步骤是这样的

PUT gym
{
  "mappings": {
    "gyms": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

插入包含位置的记录

PUT gym/gyms/1
{
  "location" : [ -71.34, 41.12 ]
}

然后查找索引及其数据类型

GET /gym/gyms/_mapping/

您将看到 location 字段具有 geo_point 数据类型。然后你就可以执行你的查询了。

GET gym/gyms/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
              "geo_distance" : {
                    "distance" : "150km",
                    "location" : [ -70.34, 40.12 ]
                }
            }
        }
    }
}

现在运行良好。

【讨论】:

    猜你喜欢
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多