【问题标题】:Using a geo_point field returns a "mixing up field types" during document insertion在文档插入期间使用 geo_point 字段会返回“混合字段类型”
【发布时间】:2016-10-26 21:31:09
【问题描述】:

我正在尝试关注documentation for geo_points。 为此,我创建了一个名为“城市”的索引

curl -X POST -H "Cache-Control: no-cache" -H -d '{
  "mappings": {
    "cities": {
      "properties": {
        "name": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "location":{
          "type": "geo_point"
        }

      }
    }
  }
}' "http://192.168.0.76:9200/cities"

我现在正尝试使用以下请求插入文档:

curl -X POST -H "Cache-Control: no-cache" -d '{
  "name": "Amsterdam",
  "location": "52.3702,4.8952"
}' "http://192.168.0.76:9200/cities/properties?pretty"

然而,这会返回以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location"
    }
  },
  "status": 400
}

对我来说,这似乎很奇怪,因为文档指出我应该能够使用字符串表示法插入文档:

将 location 字段定义为 geo_point,我们可以继续 包含纬度/经度对的索引文档,可以是 格式化为字符串、数组或对象:

字符串表示,带有“lat,lon”。

我做错了什么?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    插入时出错。您不小心插入了不同的 映射类型 properties 而不是 cities 。来自documentation不同映射类型的同名字段必须有相同的映射

    这会起作用

    curl -X POST -H "Cache-Control: no-cache" -d '{
      "name": "Amsterdam",
      "location": "52.3702,4.8952"
    }' "http://192.168.0.76:9200/cities/cities?pretty"
    

    【讨论】:

    • 很高兴能帮上忙!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多