在创建文档时,我想访问一个以“@”开头的字段。
文档将通过以下方式添加:
POST http://localhost:9200/myindex/_doc?pipeline=test_pipeline
{
"name":"Joe",
"@myfield":"field value"
}
甚至无法添加这样的管道,它会引发编译错误(使用不带“@”的字段效果很好){
"description": "describe pipeline",
"processors": [
{
"script": {
"ignore_failure": false,
"lang": "painless",
"source": "ctx._id= ctx.@myfield"
}
}
]
}
尝试此处描述的解决方案https://discuss.elastic.co/t/painless-how-to-access-timestamp-field-in-script/130263{
"description": "describe pipeline",
"processors": [
{
"script": {
"ignore_failure": false,
"lang": "painless",
"source": "ctx._id= ctx._source['@myfield']"
}
}
]
}
这样可以成功创建管道,但是以上述方式添加文档将失败,并引发NPE: "type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._id= ctx._source['@myfield']",
" ^---- HERE"
],
"script": "ctx._id= ctx._source['@myfield']",
"lang": "painless",
"position": {
"offset": 12,
"start": 0,
"end": 34
},
"caused_by": {
"type": "null_pointer_exception",
"reason": "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
}
最佳答案
这有效:"source": "ctx._id= ctx['@myfield']"
ctx._source仅在使用更新,按查询更新或重新索引API时可以访问
来源:
https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-fields.html
关于elasticsearch - Elasticsearch管道无法访问@myfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64623305/