1

I have an old index (elasticsearch index) has more than 20K objects, this index has fields

{
    "title": "Test title",
    "title_ar": "عنوان تجريبي",
    "body": "<p>......</p>"
}

I want to _reindex them to convert all data to new mapping like this

{
    "title_1": {
        "en": "Test title",
        "ar": "عنوان تجريبي"
    },
    "body": "<p>......</p>"
}

What is the best elasticsearch pipeline processor to make this conversion available in _reindex API?

Abdallah Sabri
  • 431
  • 4
  • 20

1 Answers1

2

I suggest to simply use the reindex API to do this:

POST _reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  },
  "script": {
    "source": "ctx._source.title = [ 'en' : ctx._source.title, 'ar': ctx._source.title_ar]",
    "lang": "painless"
  }
}

If in your old_index index you have this:

{
    "title": "Test title",
    "title_ar": "عنوان تجريبي",
    "body": "<p>......</p>"
}

In your new index, you'll have this:

{
    "title": {
        "en": "Test title",
        "ar": "عنوان تجريبي"
    },
    "body": "<p>......</p>"
}
Val
  • 207,596
  • 13
  • 358
  • 360