Elasticsearch Search API 基础语法
Elasticsearch Search API 基础语法，文字内容来自 B 站中华石杉 Elasticsearch 顶尖高手系列课程核心知识篇，英文内容来自官方文档。
Search your data
A search query, or query, is a request for information about data in Elasticsearch data streams or indices.
A search consists of one or more queries that are combined and sent to Elasticsearch.
Search API 的基本语法
Search API: Returns search hits that match the query defined in the request.
Allows you to execute a search query and get back search hits that match the query.
<target> (Optional, string) Comma-separated list of data streams, indices, and index alias to search. Wildcard(*) expressions are support.
from: (Optional, integer) Starting document offset. Defaults to 0.
size: (Optional, integer) Defines the number of hits to return. Defaults to 10.
By default, you cannot page through more than 10,000 hits using the from and size parameters.
sort: (Optional, string) A comma-separated list of <field>:<direction> pairs.
took: (integer) Milliseconds it took Elasticsearch to execute the request. This value is calculated by measuring the time elapsed between receipt of a request on the coordinating node and the time at which the coordinating node is ready to send the response.
Took time includes:
Communication time between the coordinating node and data nodes
Time the request spends in the search thread pool, queued for execution
Actual execution time
Took time does not include:
Time needed to send the request to Elasticsearch
Time needed to serialize the JSON response
Time needed to send the response to a client
time_out: (Boolean) If true, the request timed out before completion; returned results may be partial or empty.
hits: (object) Contains returned documents and metadata.
GET or POST
http 协议中 get 是否可以带上 request body ?
HTTP 协议，一般不允许 get 请求带上 request body，但是因为 get 更加适合描述查询数据的操作，因此还是这么用了
碰巧，很多浏览器，或者是服务器，也都支持 GET+request body 模式
如果遇到不支持的场景，也可以用 POST /_search
版权声明: 本文为 InfoQ 作者【escray】的原创文章。