# 搜索

到目前为止，我们已经学习了Elasticsearch的分布式NOSQL文档存储，我们可以直接把JSON文档扔到Elasticsearch中，然后直接通过ID来进行调取。但是Elasticsearch真正的强大之处在于将混乱变得有意义——将大数据变成大量的信息。

这也是我们使用JSON文档而不是无规则数据的原因。Elasticsearch不仅仅只是*存储*文档，同时它还*索引*了这些文档以便搜索。**文档中每一个字段都被索引并且可以被查询**。不仅如此，在一个查询中，Elasticsearch可以使用**所有**索引，并且以惊人的速度返回结果。这是传统数据库永远也不能企及的。

这个*搜索*可以是：

* 类似于`年龄`、`性别`、`加入日期`等结构化数据，类似于在SQL中进行查询。
* 全文搜索，查找整个文档中匹配关键字的内容，并根据*相关性*
* 或者结合两者。

虽然很多搜索操作是安装好Elasticsearch就可以用的，但是想发挥它的潜力，你需要明白以下内容：

| 名字               | 说明                       |
| ---------------- | ------------------------ |
| *映射 (Mapping)*   | 每个字段中的数据如何被解释            |
| *统计 (Analysis)*  | 可搜索的全文是如何被处理的            |
| *查询 (Query DSL)* | Elasticsearch使用的灵活强的查询语言 |

上述的每一个内容都是一个大的主题，我们将会在之后的《深入搜索》中详细探讨它们。 本章中我们将针对先去介绍它们三个的基本概念 —— 已经足够能帮助你理解搜索是如何运作的了。

我们将向你介绍`search`API的简单实用方式。

> ## 测试数据

我们本章使用的文档可以在下面的git中找到：<https://gist.github.com/clintongormley/8579281>

你可以下载然后导入到你的shell中以方便你的学习使用。


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
