首页 > 解决方案 > 无法从类型 [geo_point] 更改为 xxx

问题描述

映射类型是geo_point,golang应该用什么类型

我的结构:

我的代码:

结果消息:

[400 Bad Request] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [localhost] cannot be changed from type [geo_point] to [float]"}],"type":"illegal_argument_exception","reason":"mapper [localhost] cannot be changed from type [geo_point] to [float]"},"status":400}

标签: goelasticsearch

解决方案


在不知道您正在运行的查询的情况下,我可以想象您没有为 geo_point 字段类型传递正确的格式。

根据文档,您需要传递latlon属性对象。

映射

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

摄取数据

PUT my-index-000001/_doc/1
{
  "text": "Geo-point as an object",
  "location": { 
    "lat": 41.12,
    "lon": -71.34
  }
}

询问

GET /my-index-000001/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "geo_distance": {
          "distance": "200km",
          "location": {
            "lat": 40,
            "lon": -70
          }
        }
      }
    }
  }
}

如果您需要更多帮助,请附上您当前的查询


推荐阅读