是否可以通过查询别名来通过其id请求单个文档,前提是别名中所有索引的所有键都是唯一的(它是外部保证)?
答案 0 :(得分:8)
是的,查询跨越多个索引的别名与查询一个indice的方式相同。
只需对别名执行此查询:
POST my_alias_name/_search
{
"filter":{
"term":{"_id": "AUwNrOZsm6BwwrmnodbW"}
}
}
编辑:GET操作不是真正的搜索,不能跨越多个索引的别名。因此,以下查询实际上是不允许的:
GET my_alias_name/my_type/AUwNrOZsm6BwwrmnodbW
答案 1 :(得分:7)
从Elasticsearch 5.1查询看起来像:
GET /my_alias_name/_search/
{
"query": {
"bool": {
"filter": {
"term": {
"_id": "AUwNrOZsm6BwwrmnodbW"
}
}
}
}
}
答案 2 :(得分:0)
GET /_search
{
"query": {
"ids" : {
"values" : ["1", "4", "100"]
}
}
}
响应应如下所示:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "indexwhatever",
"_type": "_doc",
"_id": "anyID",
"_score": 1.0,
"_source": {
"field1": "value1",
"field2": "value2"
}
}
]
}
}
答案 3 :(得分:0)
如果您要查找带有一些带有curl的内部ID的文档:
curl -X GET 'localhost:9200/_search?q=id:42&pretty'