57.query phase

主要知识点:

  • query phase步骤
  • query phase如何提升性能

   

一、query phase步骤

一次query phase一般包括以下三个步骤

   

The query phase consists of the following three steps:

  1. The client sends a search request to Node 3, which creates an empty priority queue of size from + size.
  2. 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.
  3. 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操作fromsize为准,默认为10

2coordinate node将请求转发到所有shard,每个shard本地搜索,并构建一个本地的priority queue

3、各个shard将自己的priority queue返回给coordinate nodecoordinate node对这些priority queue 进行合并,并构建一个全局的priority queue,然后在这个priority queue得到搜索页的结果。

   

二、replica shard如何提升搜索吞吐量

   

一次请求要路由所有shard的一个replicaprimary上去,如果每个shard都有多个replica,那么同时并发过来的搜索请求可以同时打到其他的replica上去。(也就是说一请求对于一个primary shard及其他对应的所有replica shard 只会有一个shard去处理这一次请求)

   

三、延伸阅读

query phase

   

   

原文地址:https://www.cnblogs.com/liuqianli/p/8473235.html