我在弹性2.4中有一个带有父子关系的索引。
此索引有2种类型,一种是父级,第二种是子级。除了公共字段field1
之外,两者都有不同的映射。
索引映射如下所示:
类型parent
:
{
"properties": {
"field1": {
"type": "long"
},
"field2": {
"type": "long"
}
}
}
类型child
:
{
"properties": {
"field3": {
"type": "long"
},
"field1": {
"type": "long"
}
}
}
现在,我已经更新了子索引映射,并添加了另一个与父索引相同的字段,即field2。
现在,孩子的映射看起来像这样:
{
"properties": {
"field3": {
"type": "long"
},
"field1": {
"type": "long"
}
"field2": {
"type": "long"
}
}
}
现在,我想基于field1
的公共字段将值从父级复制到子级。
子索引中的文档应更新为field2
,它们具有共同的field1
。
我尝试了_reindex
api和update_by_query,但没有找到任何有效且快速的解决方案来做到这一点。正如我尝试使用如下所示的带有源和目标的_reindex
api一样,但是存在一个局限性,即它将创建新文档,而不是通过field1
这样的通用文件来更新文档。
我尝试了以下解决方案。
index_name/_reindex
{
"source": {
"index": "index_name",
"type": "parent"
},
"dest": {
"index": "index_name",
"type": "child"
},
"script": {
"inline": "ctx._dest.field2 = ctx._source.field2"
}
}
这给我一个错误,就是我们不能使用与源和目标相同的索引。我该如何解决?还是有更好的方法来做到这一点。