12
votes

I found an article on elasticsearch's site describing how to 'reindex without downtime', but that's not really acceptable every time a new element is introduced that needs to have a custom mapping (http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/)

Does anyone know why I can't create a mapping for an existing index but a new type in elasticsearch? The type doesn't exist yet, so why not? Maybe I'm missing something and it IS possible? If so, how can that be achieved?

Thanks, Vladimir

2
What have you tried to do? and what's not working? You can always create new type (with its own mapping)progrrammer
That's the point -- I don't think I can create a new type with its own mappings. Any time I try I get the following error: { "error": "IndexAlreadyExistsException[[tluseravailability] already exists]", "status": 400 }Vladimir
I think I know what are you doing, I want to verify, Can you write the json you are using to add mapping for the type?progrrammer
Here it is: { "mappings" : { "test" : { "properties" : { "test1" : { "type" : "string", "index" : "not_analyzed" }, "test2" : { "type" : "string", "index" : "not_analyzed" } } } } }Vladimir
So, it is new type you want to create? what's mapping you used to create index?progrrammer

2 Answers

21
votes

Here is a simple example to create two type mapping in a index, (one after another)

I've used i1 as index and t1 and t2 as types,

  1. Create index

    curl -XPUT "http://localhost:9200/i1"
  2. Create type 1

    curl -XPUT "http://localhost:9200/i1/t1/_mapping" -d
    {
       "t1": {
          "properties": {
             "field1": {
                "type": "string"
             },
             "field2": {
                "type": "string"
             }
          }
       }
    }'
  3. Create type 2

    curl -XPUT "localhost:9200/i1/t2/_mapping" -d'
    {
       "t2": {
          "properties": {
             "field3": {
                "type": "string"
             },
             "field4": {
                "type": "string"
             }
          }
       }
    }'

Now Looking at mapping( curl -XGET "http://localhost:9200/i1/_mapping" ), It seems like it is working.

Hope this helps!! Thanks

6
votes

If you're using Elasticsearch 6.0 or above, an index can have only one type. So you have to create an index for your second type or create a custom type that would contain the two types.

For more details : Removal of multiple types in index