0
下面是对弹性搜索的请求。对象映射错误将弹性搜索中的Json从groovy脚本添加到数组类型
post sample/item_type/1/_update
{
"script" : {
"file" : "my_script",
"params" : {
"slice_id" : 2,
"hash" : "xyjjz"
}
},
"upsert" : {
"item_body" : {
"name" : "dummy"
},
"attributes" : {
"name" : "attributes"
},
"versions": [
{
"version_id" : 1,
"begin_slice_id" : 1,
"end_slice_id" : 1,
"hash" : "xyz",
"count" : 1
}
],
"version_count" : 1
}
下面是我在上面的请求中使用的groovy脚本。
import groovy.json.JsonBuilder
Integer versionCount = ctx._source.version_count;
if (ctx._source.versions[versionCount-1].hash == hash)
{
ctx._source.versions[versionCount-1].end_slice_id = slice_id;
ctx._source.versions[versionCount-1].count++;
}
else
{
def json = new JsonBuilder()
def root = json{
"name" : "wh"
}
ctx._source.versions+=root.toString();
ctx._source.version_count += 1;
}
下面是我得到
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "object mapping for [versions] tried to parse field [null] as object, but found a concrete value"
}
],
"type": "mapper_parsing_exception",
"reason": "object mapping for [versions] tried to parse field [null] as object, but found a concrete value"
},
"status": 400
我认识这个问题的错误,版本阵列是越来越插入不同类型的对象。首先直接从查询主体,然后从groovy脚本。但是如何从groovy中插入Json而没有弹性搜索的抱怨映射。提前致谢。