Ravindra BagaleCourses & study guides मराठी

Chapter 95: Logging with Loki, Elastic Stack and CloudWatch

DevOps

95.10 Kibana KQL versus Elasticsearch Query DSL

Story (fictional teaching scenario). At a fictional Mysuru bakery, Emma from Bristol pastes a JSON query into the Kibana KQL bar. It fails because the interfaces expect different syntax.

Kibana KQL versus Elasticsearch Query DSL
Kibana KQL versus Elasticsearch Query DSL

Why

Query languages can ask similar questions without being interchangeable.

What

  • KQL here means Kibana Query Language, not Microsoft Kusto Query Language.
  • Query DSL is Elasticsearch’s JSON-based query language.
  • A bool query combines clauses; its filter clauses require matching without relevance scoring.
  • A term query matches an exact indexed term; a range query checks a bound.
  • Scoring ranks relevance; operational exact filters often do not need it.

How

  1. Identify the query interface before pasting syntax.

  2. Use field types from the mapping.

  3. State a narrow time range in the interface or query.

  4. Do not treat KQL as an aggregation pipeline; use the appropriate analytics features.

Example 1: Kibana KQL filter

  1. Read the command or request.
service: "bakery-api" AND level: "ERROR" AND latency_ms >= 800
  1. Read the result.

Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)

If the six synthetic events were indexed, two would match.
  1. Line by line: service and level are keyword fields in the example mapping. AND requires every condition. latency_ms >= 800 is numeric. Kibana’s time picker also constrains results. This is not Kusto and was not executed in Kibana.

Example 2: Elasticsearch DSL request body

  1. Read the command or request.
{"query":{"bool":{"filter":[{"term":{"service":"bakery-api"}},{"term":{"level":"ERROR"}},{"range":{"latency_ms":{"gte":800}}}]}}}
  1. Read the result.

Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)

Illustrative match count for the fixture:2 documents.
  1. Line by line: query contains one bool query. filter combines the three conditions with logical AND without scoring. term uses exact keyword values. gte means greater than or equal. The index/time scope would still need to be selected; no _search request was sent.

Ravindra Bagale's Tip

Always name which KQL you mean.

Did you understand? Let us try it once more.