3

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.

Aman Garg
  • 3,122
  • 4
  • 24
  • 32
  • Could you just put all this in a new index then ditch the old one? – doctorlove Dec 04 '18 at 13:51
  • I got your poing but problem is this I have to add one more filed along with the old fields in child index. @doctorlove – Aman Garg Dec 05 '18 at 07:14
  • I don't think I can help properly, but had a similar thing to do, and when I hand-crafted an id for each record I added, it helped in the upsert because I could find what I wanted and add new fields. – doctorlove Dec 05 '18 at 09:41

0 Answers0