用于混合字段类型的IllegalStateException

时间:2016-05-02 12:47:28

标签: elasticsearch elasticsearch-2.0

我的JSON(TMPOI_TEMPLATE)

{
"addressInfo": {
    "geopoint": {
        "lon": 48.845877,
        "lat": 8.821861,
    }
},
"poiLocation": {
    "geopoint": {
        "lon": 48.845877,
        "lat": 8.821861,
    },
    "speed": 3.0,
    "date": 1461067375605
},
"_id": "f212949c-7b67-45db-9f76-fe18bf951722"
}

我的映射(TMPOI_MAPPING)

{
"trafficmeasurepoi": {
      "properties": {
        "addressInfo": {
            "properties": {
                "geopoint": { "type" : "geo_point" },
            }
        },
        "poiLocation": {
            "properties": {
                "geopoint": { "type" : "geo_point" },
                "speed": { "type" : "double"},
                "date": { "type" : "date"}
            }
        }
     }
   }
}

我填写索引的方法

索引由另一个名为 createIndex()的方法创建。它的工作正常。但是当我尝试通过以下代码填充索引时,我将得到错误

private void fillIndex()
{
    // fill index with tmpoi data
    Map<String, Object> tmpoi = JsonLoaderUtil.loadJson(TMPOI_TEMPLATE);
    String tmPoiId = (String) tmpoi.get("_id");
    IndexRequestBuilder req = client.prepareIndex(INDEX_NAME, TMPOI_TYPE, tmPoiId).setSource(tmpoi);
    req.setRefresh(true);
    IndexResponse res = req.execute().actionGet();
}   

错误

  

MapperParsingException [无法解析];嵌套:IllegalStateException [混合字段类型:class org.elasticsearch.index.mapper.core.StringFieldMapper $ StringFieldType!= class org.elasticsearch.index.mapper.internal.IdFieldMapper $ IdFieldType on field _id];

2 个答案:

答案 0 :(得分:2)

_id是保留字段。尝试从TMPOI_TEMPLATE中删除以下行(&#34; _id&#34;:&#34; f212949c-7b67-45db-9f76-fe18bf951722&#34;)并找到另一种传递文档ID的方法。 希望它有所帮助。

答案 1 :(得分:1)

您需要从文档中删除_id