【发布时间】:2021-06-13 05:39:01
【问题描述】:
我的索引中有一个嵌套字段,其中包含多个对象。
"customFields" : [
{
"objectTypeId" : 17,
"Value" : "",
"description" : "The original author of the document",
"Name" : "Document Author"
},
{
"objectTypeId" : 17,
"Value" : "",
"description" : "Source document number",
"Name" : "Legacy document number"
},
.
.
.
]
我想创建一个脚本,可以将字段从 customFields 对象移出到单独的对象中,如下所示:
"Document_Author": {
"Description": "The original author of the document",
"Value": "Some value"
"ObjectTypeId": 17
},
"Legacy document number": {
"Description": "Source document number",
"Value": "Some value"
"ObjectTypeId": 17
},
.
.
.
我试过这样的脚本,我对弹性搜索和脚本很陌生,所以这不起作用。
POST /new_document-20/_update_by_query
{
"script" : { "inline": "for (int i = 0; i < ctx._source.customFields.length; ++i) { ctx._source.add(\"customFields[i].Name\" : { \"Value\" : \"customFields[i].Value\", \"Description\" : \"customFields[i].description\", \"objectTypeId\" : \"customFields[i].objectTypeId\"}) }",
"query": {
"bool": {
"must": [
{
"exists": {
"field": "customFields.Name"
}
}
]
}
}
}
}
我从这个指向customFields[i].Name 得到编译错误像这样:
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... d(\"customFields[i].Name\" : { \"Value\" : \"customFiel ...",
" ^---- HERE"
如何创建一个脚本来帮助我将字段从嵌套对象中移出?
【问题讨论】:
标签: elasticsearch kibana elastic-stack elasticsearch-query elasticsearch-painless