2

我的 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()的方法创建的。它工作正常。但是当我尝试通过以下代码填充索引时,我会得到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();
}   

错误

MapperParsingException[解析失败]; 嵌套:IllegalStateException [混合字段类型:类 org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != 字段 _id 上的类 org.elasticsearch.index.mapper.internal.IdFieldMapper$IdFieldType];

4

2 回答 2

2

_id 是保留字段。尝试从 TMPOI_TEMPLATE 中删除以下行 ("_id": "f212949c-7b67-45db-9f76-fe18bf951722") 并找到另一种传递文档 id 的方法。希望能帮助到你。

于 2016-05-07T22:42:16.857 回答
1

您需要_id从文档本身中删除。

于 2016-05-07T12:41:07.423 回答