Profiling a more complicated query

edit

To understand how the query trees are displayed inside the Search Profiler, let’s look at a more complicated query.

  1. Index the following data via Console:

    POST test/_bulk
    {"index":{}}
    {"name":"aaron","age":23,"hair":"brown"}
    {"index":{}}
    {"name":"sue","age":19,"hair":"red"}
    {"index":{}}
    {"name":"sally","age":19,"hair":"blonde"}
    {"index":{}}
    {"name":"george","age":19,"hair":"blonde"}
    {"index":{}}
    {"name":"fred","age":69,"hair":"blonde"}
  2. From the Search Profiler, enter "test" in the Index field above the query editor to restrict profiled queries to the test index.
  3. Replace the default match_all query in the query editor with a query that has two sub-query components and includes a simple aggregation, like the example below.

    {
       "query": {
          "bool": {
             "should": [
                {
                   "match": {
                      "name": "fred"
                   }
                },
                {
                   "terms": {
                      "name": [
                          "sue",
                          "sally"
                      ]
                   }
                }
             ]
          }
       },
       "aggs": {
          "stats": {
             "stats": {
                "field": "price"
             }
          }
       }
    }
  4. Click Profile to profile the query and visualize the results.
  5. Select the shard to view the query details.

    Profiling the more complicated query

The detail view contains a row for each query component:

  • The top-level BooleanQuery component corresponds to the bool in the query.
  • The second BooleanQuery corresponds to the terms query, which is internally converted to a Boolean of should clauses. It has two child queries that correspond to "sue" and "sally" from the terms query.
  • The TermQuery that’s labeled with "name:fred" corresponds to match: fred in the query.

If you look at the time columns, you can see that "Self time" and "Total time" are no longer identical on all the rows. Self time represents how long the query component took to execute. Total time is the time a query component and all its children took to execute. Therefore, queries like the Boolean queries often have a larger total time than self time.

Aggregations

edit

This particular query also includes a aggregation (a stats agg on the "age" field). Click Aggregation Profile to view aggregation profiling statistics (this tab is only enabled if the query being profiled contains an aggregation).

Select the name of the shard to view the aggregation details and timing breakdown.

Drilling into the first shard’s details

For more information about how the Search Profiler works, how timings are calculated, and how to interpret various results, see Profiling queries.