Elasticsearch 允许您将 _type
与 _index
一起存储。我想知道我是否要提供自己的 _id
它应该在整个索引中是唯一的吗?
最佳答案
在一起应该是唯一的
PUT so
PUT /so/t1/1
{}
PUT /so/t2/1
{}
GET /so/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "so",
"_type": "t2",
"_id": "1",
"_score": 1,
"_source": {}
},
{
"_index": "so",
"_type": "t1",
"_id": "1",
"_score": 1,
"_source": {}
}
]
}
}
原因是:在不知道文档类型的情况下,您永远无法通过索引获取文档,并且使用索引范围的查询来查询 ES 将返回包含其类型和索引的文档。
关于elasticsearch - elasticsearch ID 必须对类型或索引是唯一的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747174/