Skip to content

Instantly share code, notes, and snippets.

@hbresic
Created October 9, 2018 11:58
Show Gist options
  • Save hbresic/30ae58be8a1f68a052ba62cabd08e94b to your computer and use it in GitHub Desktop.
Save hbresic/30ae58be8a1f68a052ba62cabd08e94b to your computer and use it in GitHub Desktop.
Stored Painless script for removing junk header field in Elasticsearch reindexing process. Targets 10 and 16 length string without dash (e.g. HTTP_CPKHHLZ9WM) and excludes HTTP_CONNECTION as that is only header required of this construction.
{
"script": {
"lang": "painless",
"source": "String match = null; for (f in ctx._source.entrySet()) { def m = /^HTTP_([^_]{16}|[^_]{10})$/.matcher(f.getKey()); if (m.find() && f.getKey() != 'HTTP_CONNECTION') { match = f.getKey(); break;}} ctx._source.remove(match);"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment