elasticsearch - Elasticsearch管道无法访问@myfield

标签 elasticsearch

在创建文档时,我想访问一个以“@”开头的字段。
文档将通过以下方式添加:

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/

相关文章:

elasticsearch - 在ElasticSearch中使用AND查询字段

javascript - Elasticsearch 相当于 WHERE x = 1 AND (y = 2 OR y = 3)

ElasticSearch:使用一个查询的输出作为另一个查询的输入

elasticsearch - 在Elasticsearch中获取其文本字段仅包含数字值的文档

spring-boot - 如何忽略在spring-data-elasticsearch 4.x,Elastic 7.6的ElasticSearch中保存几个字段

.net - 我们如何使用ElasticClient(NEST)提取登录到Elasticsearch的Serilog .ForContext()对象?

java - 未应用动态映射,并且在 _mapping 中丢失

mongodb - 如何在mongodb和elasticsearch之间同步?

json - 解析Google自定义搜索API以获取Elasticsearch文档

elasticsearch - 如何在elasticsearch中用冒号搜索模式?