kibana/docs/dev-tools/searchprofiler/more-complicated.asciidoc
2020-03-16 09:58:16 -05:00

104 lines
3.1 KiB
Text

[role="xpack"]
[[profiler-complicated]]
=== Profiling a more complicated query
To understand how the query trees are displayed inside the {searchprofiler},
let's look at a more complicated query.
. Index the following data via *Console*:
+
--
[source,js]
--------------------------------------------------
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"}
--------------------------------------------------
// CONSOLE
--
. From the {searchprofiler}, enter "test" in the *Index* field to restrict profiled
queries to the `test` index.
. Replace the default `match_all` query in the query editor with a query that has two sub-query
components and includes a simple aggregation:
+
--
[source,js]
--------------------------------------------------
{
"query": {
"bool": {
"should": [
{
"match": {
"name": "fred"
}
},
{
"terms": {
"name": [
"sue",
"sally"
]
}
}
]
}
},
"aggs": {
"stats": {
"stats": {
"field": "price"
}
}
}
}
--------------------------------------------------
// NOTCONSOLE
--
. Click *Profile* to profile the query and visualize the results.
. Select the shard to view the query details.
+
[role="screenshot"]
image::dev-tools/searchprofiler/images/gs8.png["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
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.
[role="screenshot"]
image::dev-tools/searchprofiler/images/gs10.png["Drilling into the first shard's details"]
For more information about how the {searchprofiler} works, how timings are calculated, and
how to interpret various results, see
{ref}/search-profile.html#profiling-queries[Profiling queries].