Reindex w/ a regex

I have lot of indices with same prefix. In those indices, I need to keep only document that have for example the field "abc" with 7 numbers only. My indices are already index in Elastic.
It is possible , with a query or other, to reindex directly with dev tools the documents in there index that have 7 numbers in the field "abc" ?

Thanks by advance,
Viviane

Hi @vfeydel

There are a couple of ways you can handle this. One way is to use the reindex command and specify a source query with a painless script. Something like this:

POST _reindex
{
  "source": {
    "index": "source-index-name",
    "query": {
      "bool": {
        "filter": {
          "script": {
            "script": {
              "lang": "painless",
              "source": "if (doc['abc'].size() == 0) { return false;} else {return doc['abc'].value.length() == 7;}"
            }
          }
        }
      }
    }
  },
  "dest": {
    "index": "dest-index-name"
  }
}

Another way could be to use an Ingest Pipeline to do this work and call the ingest pipeline in the DEST of the reindex.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.