我设置了以下别名:
"items": {
"aliases": {
"items_0": {
"filter": {
"term": {
"accountid": "0"
}
},
"index_routing": "0",
"search_routing": "0"
}
}
}
当我在 items 索引中搜索 accountid = 0 的文档时,它会被返回。然而,当我使用 items_0 的索引搜索文档时,它不会被返回。我使用完全相同的搜索条件,只是将索引名称从 items 更改为 items_0。我在这里错过了什么吗?
最佳答案
很可能您没有使用相同的 _routing
索引您的文档值作为您在别名中指定的值。
例如,对于这些文档(其中指定了 _routing
):
POST /items/test/_bulk
{"index":{"_id":1,"_routing":0}}
{"accountid": 0}
{"index":{"_id":2,"_routing":0}}
{"accountid": 0}
{"index":{"_id":3,"_routing":0}}
{"accountid": 5}
{"index":{"_id":4,"_routing":0}}
{"accountid": 3}
运行
GET /items_0/_search
{
"query": {
"filtered": {
"filter": {
"term": {
"accountid": 0
}
}
}
}
}
返回正确的结果。因此,您需要确保您的文档已使用
_routing
进行索引。您在别名中使用的 id。
关于别名上的 ElasticSearch 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31195291/