I have an index with parent-child relation in elastic 2.4.
This index has 2 type, one is a parent and second is the child. Both have different mappings except a common field that is field1
.
Index mappings look like below:
type parent
:
{
"properties": {
"field1": {
"type": "long"
},
"field2": {
"type": "long"
}
}
}
type child
:
{
"properties": {
"field3": {
"type": "long"
},
"field1": {
"type": "long"
}
}
}
Now I have updated the child index mapping and add another field same as the parent index that is field2.
Now the mapping of child looks like this:
{
"properties": {
"field3": {
"type": "long"
},
"field1": {
"type": "long"
}
"field2": {
"type": "long"
}
}
}
Now I want to copy the value from parent to child on the basis of a common field that is field1
.
document in the child index should get updated with field2
which have the common field1
.
I tried the _reindex
api and update_by_query but did not find any good and fast solution to do the same. As I tried _reindex
api with source and destination as below, but there is the limitation that it will create new document instead of updating the document by the common fiels that is field1
.
I tried the below solution.
index_name/_reindex
{
"source": {
"index": "index_name",
"type": "parent"
},
"dest": {
"index": "index_name",
"type": "child"
},
"script": {
"inline": "ctx._dest.field2 = ctx._source.field2"
}
}
This gives me an error that we can not use the same index as source and destination. How can I fix the same? or is there a better approach to do the same.