【发布时间】:2021-01-08 16:56:48
【问题描述】:
您好,我是 elasticsearch 7.9 更新映射的新手,我遇到了一个用例,我必须将简单的字段映射更新为对象映射,在应用查询之前,我创建了一个简单的示例来测试我的目的,这里是我有什么作为初始索引映射:
{
"myindex" : {
"mappings" : {
"properties" : {
"flag" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
我想将字段名称 flag 更新为 tag 并向其添加一个名为 id 的嵌套字段,该字段将包含初始索引myindex的字段flag,我做了以下步骤:
- 使用以下映射创建了新索引 mynewindex:
PUT mynewindex/_mapping
{
"properties" : {
"tag" : {
"properties": {
"id" : {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
}
}
}
- 并使用重新索引 API:
POST _reindex
{
"source": {
"index": "myindex"
},
"dest": {
"index": "mynewindex"
},
"script": {
"source": "ctx._source.tag.id = ctx._source.remove(\"flag\")"
}
}
这给了我这个错误:
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.tag.id = ctx._source.remove(\"flag\")",
" ^---- HERE"
],
"script" : "ctx._source.tag.id = ctx._source.remove(\"flag\")",
"lang" : "painless",
"position" : {
"offset" : 15,
"start" : 0,
"end" : 47
}
}
],
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.tag.id = ctx._source.remove(\"flag\")",
" ^---- HERE"
],
"script" : "ctx._source.tag.id = ctx._source.remove(\"flag\")",
"lang" : "painless",
"position" : {
"offset" : 15,
"start" : 0,
"end" : 47
},
"caused_by" : {
"type" : "null_pointer_exception",
"reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
}
},
"status" : 400
}
在弹性doc 中找到的无痛脚本,正如我所期望的点符号工作,任何建议或解决方法使其工作!
【问题讨论】:
标签: elasticsearch elasticsearch-painless