2017-12-11 05:53:54

Elasticsearch The number of object passed must be even but was [1]

新版的elasticsearch 在调用setSource的时候传入json字符串、对象后都会爆:The number of object passed must be even but was [1].其实是新版需要传入Map类型。

使用fastjson转换成Map对象

Map data = JSONObject.parseObject((String) doc.get("json"), Map.class);

使用自带的XContentParser

XContentParser parser = XContentFactory.xContent(XContentType.JSON). createParser(NamedXContentRegistry.EMPTY, json);

然后在setSource时转换成Map类型: .setSource(parser.map())

发表回复