> For the complete documentation index, see [llms.txt](https://hezhiqiang.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hezhiqiang.gitbook.io/elasticsearch/search/empty_search.md).

# 空白搜索

搜索API最常用的一种形式就是*空白搜索*，也就是不加任何查询条件的，只是返回集群中所有文档的搜索。

```
GET /_search
```

返回内容如下（有删减）：

```javascript
{
   "hits" : {
      "total" :       14,
      "hits" : [
        {
          "_index":   "us",
          "_type":    "tweet",
          "_id":      "7",
          "_score":   1,
          "_source": {
             "date":    "2014-09-17",
             "name":    "John Smith",
             "tweet":   "The Query DSL is really powerful and flexible",
             "user_id": 2
          }
       },
        ... 9 个结果被隐藏 ...
      ],
      "max_score" :   1
   },
   "took" :           4,
   "_shards" : {
      "failed" :      0,
      "successful" :  10,
      "total" :       10
   },
   "timed_out" :      false
}
```

## `hits`

返回内容中最重要的内容就是`hits`，它指明了匹配查询的文档的`总数`，`hits`数组里则会包含前十个匹配文档——也就是搜索结果。

`hits`数组中的每一条结果都包含了文档的`_index`, `_type`以及`_id`信息，以及`_source`字段。这也就意味着你可以直接从搜索结果中获取到整个文档的内容。这与其他搜索引擎只返回给你文档编号，还需要自己去获取文档是截然不同的。

每一个元素还拥有一个`_score`字段。这个是*相关性评分*，这个数值表示当前文档与查询的匹配程度。通常来说，搜索结果会先返回最匹配的文档，也就是说它们会按照`_score`由高至低进行排列。在这个例子中，我们并没有声明任何查询，因此`_score`就都会返回`1`

`max_score`数值会显示所有匹配文档中的`_score`的最大值。

## `took`

`took`数值告诉我们执行这次搜索请求所耗费的时间有多少毫秒。

## `shards`

`_shards`告诉了我们参与查询分片的总数，以及有多少`successful`和`failed`。通常情况下我们是不会得到失败的反馈，但是有的时候它会发生。如果我们的服务器突然出现了重大事故，然后我们丢失了同一个分片中主从两个版本的数据。在查询请求中，无法提供可用的备份。这种情况下，Elasticsearch就会返回\`failed提示，但是它还会继续返回剩下的内容。

## `timeout`

`timed_out`数值告诉了我们查询是否超时。通常，搜索请求不会超时。如果相比完整的结果你更需要的是快速的响应时间，这是你可以指定`timeout`值，例如`10`、`"10ms"`（10毫秒）或者`"1s"`（1秒钟）：

```
GET /_search?timeout=10ms
```

Elasticsearch会尽可能地返回你指定时间内它所查到的内容。

> ## Timeout并不是终止者

这里应该强调一下`timeout`并不会终止查询，它只是会在你指定的时间内返回*当时*已经查询到的数据，然后关闭连接。在后台，其他的查询可能会依旧继续，尽管查询结果已经被返回了。

使用超时是因为你要保障你的品质，并不是因为你需要终止你的查询。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hezhiqiang.gitbook.io/elasticsearch/search/empty_search.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
