26in depth analysis of search results (search timeout mechanism)

1. If we send a search request, we will get a pile of search results. In this lesson, let's explain what the various data in the search results mean

Query all

GET /_search

Response results

{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 11,
    "successful": 11,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 14,
    "max_score": 1,
    "hits": [
      {
        "_index": ".kibana",
        "_type": "config",
        "_id": "5.6.0",
        "_score": 1,
        "_source": {
          "buildNum": 15523
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "8",
        "_score": 1,
        "_source": {
          "test_field": "test client 2"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "10",
        "_score": 1,
        "_source": {
          "test_field1": "test1",
          "test_field2": "updated test2"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "12",
        "_score": 1,
        "_source": {
          "test_field": "test12"
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "jiajieshi yagao",
          "desc": "youxiao fangzhu",
          "price": 25,
          "producer": "jiajieshi producer",
          "tags": [
            "fangzhu"
          ]
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "special yagao",
          "desc": "special meibai",
          "price": 50,
          "producer": "special yagao  producer",
          "tags": [
            "meibai"
          ]
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "4",
        "_score": 1,
        "_source": {
          "test_field1": "test field111111"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "6",
        "_score": 1,
        "_source": {
          "test_field": "test test"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "2",
        "_score": 1,
        "_source": {
          "test_field": "replaced test2"
        }
      },
      {
        "_index": "ecommerce",
        "_type": "product",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "gaolujie yagao",
          "desc": "gaoxiao meibai",
          "price": 30,
          "producer": "gaolujie producer",
          "tags": [
            "meibai",
            "fangzhu"
          ]
        }
      }
    ]
  }
}

A total of. kabana and test created in actual combat exercises are provided with the system_ Index and ecommerce, 3 indexes in total

Due to too much data, only part of the results can be seen

 {
     "took": 8,
     "timed_out": false,
     "_shards":
     {
         "total": 11,
         "successful": 11,
         "skipped": 0,
         "failed": 0
     },
     "hits":
     {
         "total": 14,
         "max_score": 1,
         "hits": [
         {
             "_index": ".kibana",
             "_type": "config",
             "_id": "5.6.0",
             "_score": 1,
             "_source":
             {
                 "buildNum": 15523
             }
         }]
     }
 }

took: how many milliseconds did the entire search request take

hits.total: several results were returned in this search
hits.max_score: among all the results of this search, what is the maximum relevance score? The more relevant each document is to search_ The higher the score, the higher the ranking
hits.hits: the first 10 pieces of data are queried by default, and the complete data of each document is queried according to_ score descending sort

Shards: the conditions for shards fail (primary and replica all hang up) do not affect other Shards. By default, a search request will reach all primary shards of an index. Of course, each primary shard may have one or more replica shards, so the request can also go to one of the replica shards corresponding to the primary shard.

Timeout: no timeout by default, latency balance completeness, manually specify timeout, timeout query execution mechanism

2. Let's explain the timeout mechanism of search, the underlying principle and drawing explanation

By default, when you do not set the so-called timeout, there is no timeout limit. For example, your search is particularly slow. It takes a long time for each shard to query the requested data, so your search request will not return until it is queried.

General business search requests are very time sensitive. Considering the user experience, it is impossible for users to wait for a few minutes, or even more than ten minutes, to wait for the results of search requests.

Timeout mechanism: specify each shard to return part of the searched data (or all the searched data) directly to the application within the timeout time range without long-term query. Wait until all the data is searched.

In other words, a search request can be completed within the specified timeout, providing better support for some time sensitive business searches.

Specify timeout

timeout=10ms,timeout=1s,timeout=1m

GET /_search?timeout=10s

Some of the searched data (or all of them may have been searched) are directly returned to the application without long-term query, and then returned after all the data are searched.

In other words, a search request can be completed within the specified timeout, providing better support for some time sensitive business searches.

Specify timeout

timeout=10ms,timeout=1s,timeout=1m

GET /_search?timeout=10s

Tags: ElasticSearch

Posted on Sat, 06 Nov 2021 13:51:20 -0400 by bullchina