Search code examples
elasticsearchelasticsearch-mapping

ElasticSearch Mapping Issue


I have an index and type. I used mapping and ngram analyzer. The problem is when I want to use mapping and ngram analyzer for a new type under same index, it gives me an error and force me to remove my index.

But I don't want to remove my index for new types for each mapping operation because I might continue to add new types under same index. Removing my index and indexing all documents and types again will be time and data loss for me.

Do you have any solution for this?


Solution

  • You can add new types to mapping of an existing index without having to reindex the old documents of pre-existing type.You can read about it in update mapping.

    For example if you have an index "TEST" and you want to create a new type "type_new". You could run the following :

    curl -XPUT 'http://<server>/TEST/_mapping/type_new' -d '
    {
        "TYPE_NEW" : {
            "properties" : {
                "subject" : {"type" : "string", "store" : true }
            }
        }
    }'
    

    However if you are going to add a new analyzer to the existing index then you would need to close the index update the settings and then reopen.You can look at update settings for more information.