0

I am trying to migrate from ES 1.4 to ES 5.5. In one of the index, I need to change the name of field and also convert it's value to uppercase. I am able to reindex with a change in name of field and remove the unwanted field but need help in converting the value to uppercase.

This is what I tried

POST _reindex?wait_for_completion=false
{
  "source": {
    "remote": {
      "host": "http://source_ip:17002"
    },
    "index": "log_event_2017-08-11",
    "size": 1000,
    "query": {
      "match_all": {}
    }
  },
  "dest": {
    "index": "logs-ics-2017-08-11"
  },
  "script": {
    "inline": "ctx._source.product = ctx._source.remove(\"product_name\")",
    "lang": "painless"
  }
}

The above POST request is able to remove "product_name" and create "product" with it's value. So in order to uppercase "product" docs value I tried below inline script but it gives a null_pointer_exception.

I am new to Elasticsearch scripting. Please help.

"ctx._source.product = ctx._source.remove(\"product_name\");ctx._source.product = doc[\"product\"].toUpperCase()"

1 Answers1

0

You can add an ingest pipeline before you trigger the _reindexapi. There are processors to rename a field and convert a field to uppercase. You can incorporate the pipeline in your reindex call, then.

{
  "source": {
    "index": "source"
  },
  "dest": {
    "index": "dest",
    "pipeline": "<id_of_your_pipeline>"
  }
}
Ravi Naik
  • 739
  • 7
  • 6