我在 ES 中存储了这样的模式:
{
"userId123": {
"userPhoneInfo": {
"phoneBrand": "Apple",
"phoneOS": "IOS"
},
"userName": "XYZ",
"userPhoneNo": "ABCDEFG"
}
}
这里 userId123 是 _id。我想更新 userPhoneInfo。它可以为 null 或具有 json 值。下面 _update_by_query 适用于这两种情况
{
"query": {
"match": {
"userPhoneNo": "ABCDEFG"
}
},
"script": {
"source": "ctx._source.userPhoneInfo=params.userPhoneInfo;ctx._source.userName=params.userName;",
"lang": "painless",
"params": {
"userPhoneInfo" : {
"phoneBrand": "OnePlus",
"phoneOS": "android",
},
"userName":"XYZ"
}
}
}
在java中,我使用了以下脚本和parmas:
new Script(Script.DEFAULT_SCRIPT_TYPE,
Script.DEFAULT_SCRIPT_LANG,
"ctx._source.userPhoneInfo.phoneBrand = params.phoneBrand;" +
"ctx._source.userPhoneInfo.phoneOS = params.phoneOS;",
params);
Map<String, Object> params = new HashMap<>();
params.put("phoneBrand", "OnePlus");
params.put("phoneOS", "android");
但得到这个例外:!org.elasticsearch.ElasticsearchException: Elasticsearch 异常 [type=null_pointer_exception, reason=null] !在 org.elasticsearch.ElasticsearchException.innerFromXContent
如果我使用这样的脚本和参数
new Script(Script.DEFAULT_SCRIPT_TYPE,
Script.DEFAULT_SCRIPT_LANG,
"ctx._source.userPhoneInfo = params.userInfo;",
params);
Map<String, Object> params = new HashMap<>();
params.put("userPhoneInfo", new UserPhoneInfo("OnePlus","android"));
得到这个例外!java.lang.IllegalArgumentException:无法为类型类 com.ffb.pno.dtos.listingMeta.PPUAttributes 的未知值写入 xcontent!在 org.elasticsearch.common.xcontent.XContentBuilder.unknownValue
请帮助我我做错了什么