12

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

8
  • What have you tried to do? and what's not working? You can always create new type (with its own mapping) Commented Aug 18, 2014 at 4:54
  • 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 } Commented Aug 19, 2014 at 3:11
  • 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? Commented Aug 19, 2014 at 3:21
  • Here it is: { "mappings" : { "test" : { "properties" : { "test1" : { "type" : "string", "index" : "not_analyzed" }, "test2" : { "type" : "string", "index" : "not_analyzed" } } } } } Commented Aug 19, 2014 at 4:12
  • So, it is new type you want to create? what's mapping you used to create index? Commented Aug 19, 2014 at 4:15

2 Answers 2

22

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I was missing the type after the index, and have to set the mapping after index creation.
6

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

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.