Reputation: 272094
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?
Upvotes: 0
Views: 142
Reputation: 2294
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.
Upvotes: 0