Is it possible to update an existing field in an i

2019-03-06 02:02发布

问题:

I've already created an index, and it contains data from my MySQL database. I've got few fields which are string in my table, where I need them as different types (integer & double) in Elasticsearch.

So I'm aware that I could do it through mapping as follows:

{
  "mappings": {
    "my_type": {
      "properties": {
        "userid": {
          "type": "text",
          "fielddata": true
        },
        "responsecode": {
          "type": "integer"
        },
        "chargeamount": {
          "type": "double"
        }
      }
    }
  }
} 

But I've tried this when I'm creating the index as a new one. What I wanted to know is how can I update an existing field (ie: chargeamount in this scenario) using mapping as a PUT?

Is this possible? Any help could be appreciated.

回答1:

Once a mapping type has been created, you're very constrained on what you can update. According to the official documentation, the only changes you can make to an existing mapping after it's been created are the following, but changing a field's type is not one of them:

In general, the mapping for existing fields cannot be updated. There are some exceptions to this rule. For instance:

  • new properties can be added to Object datatype fields.
  • new multi-fields can be added to existing fields.
  • doc_values can be disabled, but not enabled.
  • the ignore_above parameter can be updated.