IllegalStateException for mixing up field types

喜夏-厌秋 提交于 2019-12-08 01:52:40

问题


My 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"
}

My Mappings (TMPOI_MAPPING)

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

My method to fill the index

Index is created by another method called createIndex(). Its working fine. But when i try to fill the index by following code i will get ERROR

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();
}   

ERROR

MapperParsingException[failed to parse]; nested: IllegalStateException[Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.internal.IdFieldMapper$IdFieldType on field _id];


回答1:


_id is a reserved field. Try to remove the following line ("_id": "f212949c-7b67-45db-9f76-fe18bf951722") from the TMPOI_TEMPLATE and find another way to pass the document id. Hope it helps.




回答2:


You'll need to delete _id from the document itself.



来源:https://stackoverflow.com/questions/36982849/illegalstateexception-for-mixing-up-field-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!