1

Trying to test out re-index API in elasticsearch and running into issues where existing data contains fields not present in the new index's strict mapping. Is there a way to tell elasticsearch to simply ignore those fields and carry on?

Edit: To clarify, by ignore I meant not to include those fields during the re-index process.

3
  • 1
    can you adjust the mapping settings before starting the reindex? or you don't have access to it? Commented Sep 11, 2019 at 21:33
  • @AndreyBorisko I can but I want the fields ignored, or i guess removed, during the re-index. Is that even possible? Commented Sep 11, 2019 at 21:50
  • it's possible. might look dirty though. depending on how many properties you need to remove. Commented Sep 11, 2019 at 23:16

2 Answers 2

2

If you have access to the index settings before running reindex you can just do:

PUT test/_mapping
{
    "dynamic": "false"
}

then change it back to strict once reindexing is done.

UPDATE based on your comment

POST _reindex
{
  "source": {
    "index": "src"
  },
  "dest": {
    "index": "dst"
  },
  "script": {
    "lang": "painless",
    "source": """
    ctx['_source'].remove('email');
    ctx['_source'].remove('username');
    ctx['_source'].remove('name');
    // removing from nested:
    for(item in ctx['_source'].Groups){
        item.remove('GroupName');
        item.remove('IsActive');
    }
    """
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

That lets me insert the data, however I would like any excess fields removed.
It seems you have to specify the individual fields you want versus remove anything not in the schema.
0

While reindexing you can include or exclude source fields according to your destination index mapping.

To exclude some specific fields while reindexing:

POST _reindex
{
  "source": {
    "index": "source-index",
    "_source": {
      "excludes": ["exclude_a", "exclude_b"]
    }
  },
  "dest": {
    "index": "dest-index"
  }
}

To include any specific field while reindexing:

POST _reindex
{
  "source": {
    "index": "source-index",
    "_source": ["include_a", "include_b"]
  },
  "dest": {
    "index": "dest-index"
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.