Search code examples
elasticsearchtextintegermappingschema

Reindex documents, text and integer fields in elasticsearch 7


GET paganotti_civile_nuovo/_search
{
  "query": {
    "match": {
      "numerosentenza": 1105
    }
  }
}

Run this query in elasticsearch 7 it return these fields:

"codicesezione" : "S1",
"senderid" : "DVSDRD44E18E438B",
"numerosentenza" : "1105",
"_version_" : "1607812642583347200",

numerosentenza is text because "1105", but I set mapping paganotti_civile_nuovo numerosentenza as integer. You can see here:

GET paganotti_civile_nuovo/_mapping/field/numerosentenza
{
  "paganotti_civile_nuovo" : {
    "mappings" : {
      "numerosentenza" : {
        "full_name" : "numerosentenza",
        "mapping" : {
          "numerosentenza" : {
            "type" : "integer"
          }
        }
      }
    }
  }
}

I done reindex in this way:

POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "paganotti_civile"
  },
  "dest": {
    "index": "paganotti_civile_nuovo"
  },
  "script": {
    "lang": "painless",
    "source": "ctx._id = ctx._source._id"
  }
}

Solution

  • It works by design. If the field mapping is set to integer but you sent a stringified integer "1105" instead of an integer value 1105, it's ok as ES will automatically try to coerce the string value into the integer value.

    However, ES will NOT modify your source document, so if you send "1105", you'll retrieve "1105" from your _source document even though 1105 is actually indexed.