5

Is it possible to modify property of an existing field from not_analyzed to analyzed ?

If not, what can I do in order to keep all my documents in store ?

I cannot delete mappings (because then all documents will be gone) and I need that old field as analyzed.

2
  • What version of ES are you running? Commented Apr 6, 2016 at 8:20
  • @Val ES ver. 2.2.0 Commented Apr 6, 2016 at 10:12

2 Answers 2

11

You cannot modify an existing field, however, you can either create another field or add a sub-field to your not_analyzed field.

I'm going for the latter solution. So first, add a new sub-field to your existing field, like this:

curl -XPUT localhost:9200/index/_mapping/type -d '{
    "properties": {
        "your_field": {
            "type": "string",
            "index": "not_analyzed",
            "fields": {
                "sub": {
                    "type": "string"
                }
            }
        }
    }
}'

Above, we've added the sub-field called your_field.sub (which is analyzed) to the existing your_field (which is not_analyzed)

Next, we'll need to populate that new sub-field. If you're running the latest ES 2.3, you can use the powerful Reindex API

curl -XPUT localhost:9200/_reindex -d '{
  "source": {
    "index": "index"
  },
  "dest": {
    "index": "index"
  },
  "script": {
    "inline": "ctx._source.your_field = ctx._source.your_field"
  }
}'

Otherwise, you can simply use the following Logstash configuration which will re-index your data in order to populate the new sub-field

input {
  elasticsearch {
   hosts => "localhost:9200"
   index => "index"
   docinfo => true
  }
}
filter {
 mutate {
  remove_field => [ "@version", "@timestamp" ]
 }
}
output {
 elasticsearch {
   hosts => ["localhost:9200"]
   manage_template => false
   index => "%{[@metadata][_index]}"
   document_type => "%{[@metadata][_type]}"
   document_id => "%{[@metadata][_id]}"
 }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Sure thing, here you go.
THANK YOU Val ! :)
Always glad to help!!
Hi, Got two questions: 1. I don't really understand why we should do the "reindex" part. If we are adding the sub_field to the existing mapping (first part), that's not enough ? Why should we reindex ? 2. If we are added a subfield, does my field insert will be affected ? I mean will I continue sending: curl -XPUT localhost:9200/index/ -d { "my_field" : "value" } or there is any change ?
1. Because the new sub-field you created doesn't contain any data yet, that's why you need to populate it. 2. By creating a sub-field, you have nothing else to modify in your indexing process, you can do exactly the same as you used to.
|
0

https://www.elastic.co/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html

You can use this... there is something known as multi field type mapping, which allows you to have more than one mapping for a single field, and you can also query based on the field type..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.