Skip to content

Instantly share code, notes, and snippets.

@michaelkeevildown
Last active March 12, 2020 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelkeevildown/c20d21009538f29569ea7cc93d88be3f to your computer and use it in GitHub Desktop.
Save michaelkeevildown/c20d21009538f29569ea7cc93d88be3f to your computer and use it in GitHub Desktop.
Reindex Elasticsearch Data With Script

How to reindex data and using inline (painless) script

PUT /data/logs/1
{
  "title": "This is a document",
  "one": 1,
  "two": 2
}
DELETE /new_data/_search
GET /new_data/_search
POST /_reindex
{
  "source": {
    "index": "data"
  },
  "dest": {
    "index": "new_data"
  },
  "script": {
    "lang": "painless",
    "inline": "ctx._source.three = ctx._source.one + ctx._source.two"
  }
}
GET /new_data/logs/1

Elasticsearch Response

{
  "_index": "new_data",
  "_type": "logs",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "one": 1,
    "title": "This is a document",
    "two": 2,
    "three": 3
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment