如何在elasticsearch中为两种类型创建Map?

hwamh0ep  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(2)|浏览(381)

我想索引用户ID和标签ID。
我将put请求发送到 https://ip//elasticsearch/myIndex ```
{
"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
}

如何解决此错误?
tuwxkamq

tuwxkamq1#

如@ben5556所述,在elasticsearch 6+中,每个索引只能有一个类型。但是,您可以通过包含自己的“类型”字段来模拟每个索引的多个类型。 { "mappings" : { "ids" : { "properties" : { "id" : {"type": "keyword" } "type": {"type": "keyword" } } } } } 然后,在为文档编制索引时,将包含“type”: { "type": "user", "id": "12345" } 这将允许您在查询索引时按类型进行筛选(使用termsquery)。这就是elasticsearch在幕后为您所做的一切,不管怎样,当它支持多种类型时。

deikduxw

deikduxw2#

在elastic 6.x中,Map类型不能超过1个。使用单一Map类型。而是使用自定义类型字段。请参阅此链接和此链接。

相关问题