Query profiling

A new feature available in Elasticsearch 5.x is the profile API. This allows the user to track the time spent by Elasticsearch in executing a search or an aggregation.

Getting ready

You will need an up-and-running Elasticsearch installation as used in the Downloading and installing Elasticsearch recipe in Chapter 2Downloading and Setup.

To execute curl via a command line, you need to install curl for your operating system.

To correctly execute the following commands, you will need an index populated with the chapter_05/populate_query.sh script available in the online code.

How to do it...

The steps to profile a query are as follows:

  1. From the command line, we will execute a search with the profile set to true, as follows:
            curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?
            pretty' -d '{
                "profile": true,
                "query": {
                    "term": {
                        "uuid": "11111"
                    }
                }
            }'
    
  2. The result returned by Elasticsearch, if everything works, should be as follows:
            { 
              "took" : 14, 
              "timed_out" : false, 
              "_shards" : {...}, 
              "hits" : {...}, 
              "profile" : { 
                "shards" : [ 
                  { 
                    "id" : "[LNeNHh8wS_SHK7AfBzjJ0A][test-index][1]", 
                    "searches" : [ 
                      { 
                        "query" : [ 
                          { 
                           "type" : "BooleanQuery", 
                           "description" : "+uuid:11111 #
                           (ConstantScore(_type:test-type))^0.0", 
                            "time" : "0.4339050000ms", 
                            "breakdown" : { 
                             "score" : 0, 
                             "build_scorer_count" : 0, 
                             "match_count" : 0, 
                             "create_weight" : 433904, 
                             "next_doc" : 0, 
                             "match" : 0, 
                             "create_weight_count" : 1, 
                             "next_doc_count" : 0, 
                             "score_count" : 0, 
                             "build_scorer" : 0, 
                             "advance" : 0, 
                             "advance_count" : 0 
                            }, 
                           "children" : [ 
                              { 
                               "type" : "TermQuery", 
                               "description" : "uuid:11111", 
                               "time" : "0.3952920000ms", 
                                "breakdown" : { 
                                "score" : 0, 
                                "build_scorer_count" : 0, 
                                "match_count" : 0, 
                                "create_weight" : 395291, 
                                "next_doc" : 0, 
                                "match" : 0, 
                                "create_weight_count" : 1, 
                                "next_doc_count" : 0, 
                                "score_count" : 0, 
                                "build_scorer" : 0, 
                                "advance" : 0, 
                                "advance_count" : 0 
                                } 
                             }, 
                              ... 
                           ] 
                          } 
                        ], 
                       "rewrite_time" : 229995, 
                       "collector" : [ 
                         { 
                            "name" : "SimpleTopScoreDocCollector", 
                            "reason" : "search_top_hits", 
                            "time" : "0.004353000000ms" 
                          } 
                        ] 
                      } 
                    ], 
                    "aggregations" : [ ] 
                  }... 
                ] 
              } 
            } 
    

The output is very verbose. It's divided for shard and for single hit.

How it works...

The profile APIs are introduced in Elasticsearch 5.x for tracking times in executing queries and aggregations.

When a query is executed, if profiling is activated, all the internal calls are tracked using the internal instrumental API. For this reason, the profile API adds an overhead to the computation.

The output is also very verbose and depends on the internal components of both Elasticsearch and Lucene, so the format of the result can change in the future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.73