Home > database >  ElasticSearch Update documents after mapping update
ElasticSearch Update documents after mapping update

Time:01-27

Im having an issue after mapping update. I've added some multi-fields to my document fields with such a request:

PUT /user/_mapping/_doc
{
  "properties": {
    "achievements": {
      "type": "nested",
      "properties": {
        "description": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}

But now I'm unable to search using achievement.name.keyword. How do I update my old data to have a new updated mapping and to be searchable with .keyword?

ES version 6.8

CodePudding user response:

After updating the index mapping, in order to perform a search on achievement.name.keyword, you need to reindex the data again in the index.

Once the data is indexed (based on the new index mapping), you can perform a search on achievement.name.keyword.

OR the other way is that you create a new index with the new index mapping, and use the reindex API, to index the data from old index to new index.

POST _reindex
{
  "source": {
    "index": "<old-index>"
  },
  "dest": {
    "index": "<new-index>"
  }
}

CodePudding user response:

I've found a solution. You can update mapping with query and all of the documents (that fulfill query criteria) will be updated with new mapping.

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

  •  Tags:  
  • Related