12

Is it possible to request a single document by its id by querying an alias, provided that all keys across all indices in the alias are unique (it is an external guarantee)?

4

4 回答 4

13

从 Elasticsearch 5.1 开始,查询看起来像:

GET /my_alias_name/_search/
{
    "query": { 
        "bool": {
         "filter": {
                "term": {
                   "_id": "AUwNrOZsm6BwwrmnodbW"
                }
            }
        }
    }
}
于 2017-10-11T07:08:25.910 回答
11

是的,查询跨越多个索引的别名与查询一个索引的方式相同。

只需对别名执行此查询:

POST my_alias_name/_search
{
    "filter":{
        "term":{"_id": "AUwNrOZsm6BwwrmnodbW"}
    }
}

编辑: GET 操作不是真正的搜索,不能对跨越多个索引的别名进行。所以下面的查询实际上是不允许的:

GET my_alias_name/my_type/AUwNrOZsm6BwwrmnodbW
于 2015-03-12T14:02:58.010 回答
3

7.2版本文档建议:

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"
        }
      }
    ]
  }
}
于 2019-07-18T12:10:01.497 回答
1

如果您想使用 curl 查找具有某些内部 id 的文档:

curl -X GET 'localhost:9200/_search?q=id:42&pretty'
于 2020-04-03T16:17:08.380 回答