0

I would like to index user IDs and tag IDs.

I send a PUT request to https://ip//elasticsearch/myIndex

{ 
  "mappings" : {
    "users" : {
      "properties" : {
        "id" : {"type": "keyword" }
      }
    },
    "tags" : {
      "properties" : {
        "id" : {"type": "keyword" }
      }
    }
  }
}

However, I receive this response:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Rejecting mapping update to [myIndex] as the final mapping would have more than 1 type: [users, tags]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [myIndex] as the final mapping would have more than 1 type: [users, tags]"
    },
    "status": 400
}

How can I solve this error?

2 Answers 2

3

From Elastic 6.x you cannot have more than 1 mapping type. Use a single mapping type. Instead use custom type field. See this link and also this link.

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

Comments

0

As stated by @ben5556, you can only have one type per index in elasticsearch 6+. However, you can mimic multiple types per index by including your own "type" field.

{ "mappings" : { "ids" : { "properties" : { "id" : {"type": "keyword" } "type": {"type": "keyword" } } } } }

Then when you index a document, you include the "type":

{ "type": "user", "id": "12345" }

This will allow you to filter by type when querying the index (using a termsQuery). Which is all elasticsearch was really doing behind the scenes for you anyways back when it supported multiple types.

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.