主要知识点:
- query phase步骤
- query phase如何提升性能
一、query phase步骤
一次query phase一般包括以下三个步骤
The query phase consists of the following three steps:
- The client sends a search request to Node 3, which creates an empty priority queue of size from + size.
- Node 3 forwards the search request to a primary or replica copy of every shard in the index. Each shard executes the query locally and adds the results into a local sorted priority queue of size from + size.
- Each shard returns the doc IDs and sort values of all the docs in its priority queue to the coordinating node, Node 3, which merges these values into its own priority queue to produce a globally sorted list of results.
1、搜索请求发送到某一个coordinate node(node3),构构建一个priority queue,长度以paging操作from和size为准,默认为10
2、coordinate node将请求转发到所有shard,每个shard本地搜索,并构建一个本地的priority queue
3、各个shard将自己的priority queue返回给coordinate node,coordinate node对这些priority queue 进行合并,并构建一个全局的priority queue,然后在这个priority queue得到搜索页的结果。
二、replica shard如何提升搜索吞吐量
一次请求要路由所有shard的一个replica或primary上去,如果每个shard都有多个replica,那么同时并发过来的搜索请求可以同时打到其他的replica上去。(也就是说一请求对于一个primary shard及其他对应的所有replica shard 只会有一个shard去处理这一次请求)
三、延伸阅读