我想索引用户ID和标签ID。
我向https://ip//elasticsearch/myIndex
发送了一个PUT请求
{
"mappings" : {
"users" : {
"properties" : {
"id" : {"type": "keyword" }
}
},
"tags" : {
"properties" : {
"id" : {"type": "keyword" }
}
}
}
}
但是,我收到此回复:
{
"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
}
如何解决此错误?
答案 0 :(得分:3)
答案 1 :(得分:0)
如@ ben5556所述,elasticsearch 6+中每个索引只能有一种类型。但是,您可以通过包含自己的“类型”字段来模拟每个索引的多种类型。
{
"mappings" : {
"ids" : {
"properties" : {
"id" : {"type": "keyword" }
"type": {"type": "keyword" }
}
}
}
}
然后,当您为文档建立索引时,您将包括“类型”:
{
"type": "user",
"id": "12345"
}
这将允许您在查询索引时使用类型进行过滤(使用termsQuery)。当它支持多种类型时,elasticsearch真正为您做的所有幕后工作。