2
我有一个下面的文档如何更新嵌套文件内阵列中elasticsearch
{
"uuid": "123",
"FirstName": "personFirstNmae",
"LastName": "personLastName",
"Inbox": {
"uuid": "121",
"messageList": [
{
"uuid": "321",
"Subject": "subject1",
"Delete": {
"deleteStatus": 0,
"deleteReason": 0
}
},
{
"uuid": "123",
"Subject": "subject",
"Delete": {
"deleteStatus": 0,
"deleteReason": 0
}
}
]
}
}
,这里是映射
{
"arteciatedb" : {
"mappings" : {
"directUser" : {
"properties" : {
"FirstName" : {
"type" : "string",
"store" : true
},
"Inbox" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"messageList" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"Delete" : {
"type" : "nested",
"include_in_parent" : true,
"properties" : {
"deleteReason" : {
"type" : "integer",
"store" : true
},
"deleteStatus" : {
"type" : "integer",
"store" : true
}
}
},
"Subject" : {
"type" : "string",
"store" : true
},
"uuid" : {
"type" : "string",
"store" : true
}
}
},
"uuid" : {
"type" : "string",
"store" : true
}
}
},
"Inbox.uuid" : {
"type" : "string"
},
"LastName" : {
"type" : "string",
"store" : true
},
"uuid" : {
"type" : "string",
"store" : true
}
}
}
}
}
}
现在我想的deleteStatus
值从0更新为1这个字段在阵列嵌套文件里这个字段的完整路径是
Inbox.messageList.Delete.deleteStatus
我在尝试做这样的
var params:java.util.Map[String,Object] = Maps.newHashMap();
params.put("updateMap","1")
val response = client.prepareUpdate("testdb", "directUser", directUserObj.getUuid)
.setScript("ctx._source.Inbox.messageList.Delete.deleteStatus = updateMap",ScriptService.ScriptType.INLINE)
.setScriptParams(params)
.execute().actionGet();
,但它提供了以下错误
org.elasticsearch.ElasticsearchIllegalArgumentException: failed to execute script
at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:202)
at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:176)
at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:170)
at org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$AsyncSingleAction$1.run(TransportInstanceSingleOperationAction.java:187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.script.groovy.GroovyScriptExecutionException: IllegalArgumentException[argument type mismatch]
at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:278)
at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:198)
... 6 more
当我试图做到这一点我已经加入这一行
script.engine.groovy.inline.update: on
在elasticsearch YML文件 也像这样
params.put("updateMap","12345")
val response = client.prepareUpdate("testdb", "directUser", directUserObj.getUuid)
.setScript("ctx._source.Inbox.uuid = updateMap",ScriptService.ScriptType.INLINE)
.setScriptParams(params)
.execute().actionGet();
那么该值没有任何错误更新,然后我的文档变得
{
"uuid": "123",
"FirstName": "personFirstNmae",
"LastName": "personLastName",
"Inbox": {
"uuid": "12345",
"messageList": [
{
"uuid": "321",
"Subject": "subject1",
"Delete": {
"deleteStatus": 0,
"deleteReason": 0
}
},
{
"uuid": "123",
"Subject": "subject",
"Delete": {
"deleteStatus": 0,
"deleteReason": 0
}
}
]
}
}
请指导我如何更新从0 deleteStatus
字段的值设为1,什么我做错了
映射是什么样的? – eemp