Guide
Kibana Dev Tools: Elasticsearch and OpenSearch query examples
In Kibana Dev Tools, each request is an HTTP method and path followed by a JSON body, such as GET /order_lines/_search with {"query": {"match": {"product": "tent"}}}. Use match for full text, term for exact keyword values, bool to combine conditions and aggs to summarise. The same syntax works in OpenSearch Dashboards. Below are copyable examples on one shop's orders.
Kibana Dev Tools console syntax
Open Kibana, find Dev Tools in the menu (or the global search), and you get Console. OpenSearch Dashboards has the same Dev Tools console. Each request is an HTTP method and a path, optionally followed by a JSON body:
# Comments start with # or //
GET /orders/_search
{
"query": { "match_all": {} }
}Ctrl+Enter (Cmd+Enter on Mac) runs the request under the cursor; select several to run them one after another. Console sends them to the cluster Kibana is connected to, and its Copy as menu turns a request into curl. The same request from a terminal:
curl --cacert http_ca.crt -u elastic -H 'Content-Type: application/json' \
'https://localhost:9200/orders/_search' -d '{"query": {"match_all": {}}}'The examples below work in Elasticsearch 8 and 9 and OpenSearch 2 and 3 unless a section says otherwise.
The example data
Every example uses one shop's data in two indices: orders and order_lines. The mapping matters, because text and keyword fields behave differently:
PUT /order_lines
{
"mappings": {
"properties": {
"order_id": { "type": "integer" },
"product": { "type": "text", "fields": { "keyword": { "type": "keyword" } } },
"category": { "type": "keyword" },
"quantity": { "type": "integer" },
"revenue": { "type": "double" },
"ordered_at": { "type": "date" }
}
}
}In orders, status, ship_country and channel are keyword, total is double, refunded is boolean and ordered_at is date. One order:
{ "order_id": 58213, "customer_id": 1042, "ordered_at": "2026-10-14T09:31:00",
"status": "delivered", "ship_country": "United Kingdom", "channel": "email",
"total": 288.0, "items": 2, "refunded": false, "categories": ["Cooking", "Tents"] }match, match_phrase and term
A text field is analyzed when it is indexed: "Ridgeline 2P tent" is stored as the tokens ridgeline, 2p and tent. A keyword field is stored exactly as written. Pick the query to match.
match analyzes your text the same way and finds documents with any of the words, best matches first. Add "operator": "and" to require all of them:
GET /order_lines/_search
{
"query": { "match": { "product": { "query": "ridgeline tent", "operator": "and" } } }
}match_phrase wants the words together and in order:
GET /order_lines/_search
{
"query": { "match_phrase": { "product": "Ridgeline 2P tent" } }
}term does no analysis and looks for the exact value. Use it on keyword, number, date and boolean fields, and terms for a list of values:
GET /order_lines/_search
{
"query": { "term": { "product.keyword": "Ridgeline 2P tent" } }
}
GET /orders/_search
{
"query": { "terms": { "status": ["pending", "processing"] } }
}The classic mistake is term on a text field. {"term": {"product": "Ridgeline 2P tent"}} returns nothing, because no single stored token equals that string. Elasticsearch's documentation says plainly: avoid term for text fields. Keyword values are case-sensitive; term takes "case_insensitive": true when you need it.
bool: must, filter, should, must_not
bool combines queries:
must: must match, and adds to the relevance score.filter: must match, but doesn't score, so it can be cached. Use it for yes/no conditions.should: optional. With nomustorfilter, at least oneshouldmust match; otherwiseshouldonly raises the score.must_not: must not match.
Shipped or delivered UK orders of 200 or more that weren't refunded, with email orders ranked first:
GET /orders/_search
{
"query": {
"bool": {
"filter": [
{ "terms": { "status": ["shipped", "delivered"] } },
{ "term": { "ship_country": "United Kingdom" } },
{ "range": { "total": { "gte": 200 } } }
],
"must_not": [ { "term": { "refunded": true } } ],
"should": [ { "term": { "channel": "email" } } ]
}
}
}Because a filter is present, the should clause doesn't exclude anything. Add "minimum_should_match": 1 to make it required.
Dates, ranges and missing fields
range takes gt, gte, lt and lte. October's orders, with a half-open range so nothing on 31 October is missed:
GET /orders/_search
{
"query": {
"range": { "ordered_at": { "gte": "2026-10-01", "lt": "2026-11-01", "time_zone": "Europe/London" } }
}
}Date math works too: "gte": "now-30d/d" means 30 days ago, rounded down to midnight. Without time_zone, dates without an offset are read as UTC.
exists finds documents with a value in a field. null and empty arrays don't count, so orders with no country are:
GET /orders/_search
{
"query": { "bool": { "must_not": { "exists": { "field": "ship_country" } } } }
}wildcard and prefix, and what they cost
GET /order_lines/_search
{
"query": { "prefix": { "product.keyword": "Ridgeline" } }
}
GET /order_lines/_search
{
"query": { "wildcard": { "product.keyword": { "value": "*tent", "case_insensitive": true } } }
}Both work on terms, not on analysed words, so use them on keyword fields. They are much slower than term or match: a pattern that starts with * or ? has to check every term in the field, and Elasticsearch's documentation says to avoid that. Clusters with search.allow_expensive_queries set to false refuse wildcard queries altogether. For "contains a word", match on the text field is the right tool.
Sorting, paging and choosing fields
size sets how many hits come back (10 by default), from skips hits, sort orders them and _source picks the fields returned. Page 3 of pending orders, newest first:
GET /orders/_search
{
"size": 20,
"from": 40,
"sort": [ { "ordered_at": "desc" }, { "order_id": "desc" } ],
"_source": ["order_id", "status", "total", "ordered_at"],
"query": { "term": { "status": "pending" } }
}The second sort field breaks ties so pages don't overlap. from + size can't go past 10,000 hits by default (index.max_result_window). To go deeper, open a point in time (PIT) and page with search_after, passing the sort values of the last hit you received:
POST /orders/_pit?keep_alive=1m # Elasticsearch
POST /orders/_search/point_in_time?keep_alive=1m # OpenSearch
GET /_search
{
"size": 20,
"pit": { "id": "<id from the call above>", "keep_alive": "1m" },
"sort": [ { "ordered_at": "desc" }, { "order_id": "desc" } ],
"search_after": [1791970260000, 58213]
}The search has no index in the path, because the PIT already names it. Elastic no longer recommends the scroll API for deep paging.
Aggregations
Aggregations summarise matching documents. Set "size": 0 when you only want the summary. Orders and revenue by status over the last year:
GET /orders/_search
{
"size": 0,
"query": { "range": { "ordered_at": { "gte": "now-12M/M" } } },
"aggs": {
"status": {
"terms": { "field": "status" },
"aggs": {
"revenue": { "sum": { "field": "total" } },
"avg_order": { "avg": { "field": "total" } }
}
}
}
}Refunded orders per month, which is how a spike shows up:
GET /orders/_search
{
"size": 0,
"query": { "term": { "refunded": true } },
"aggs": {
"month": { "date_histogram": { "field": "ordered_at", "calendar_interval": "month" } }
}
}Aggregations nest. The three biggest categories each month, with their revenue:
GET /order_lines/_search
{
"size": 0,
"aggs": {
"month": {
"date_histogram": { "field": "ordered_at", "calendar_interval": "month" },
"aggs": {
"categories": {
"terms": { "field": "category", "size": 3 },
"aggs": { "revenue": { "sum": { "field": "revenue" } } }
}
}
}
}
}Points to know: terms returns the top 10 buckets unless you set size; its counts can be approximate on indices with several shards; it orders by document count, and Elastic warns that ordering by a sub-aggregation can give wrong results; and it can't run on a text field, so use the .keyword sub-field. calendar_interval takes calendar units such as month or 1M; use fixed_interval for spans like 30m.
Counting and looking around the cluster
GET /orders/_count
{
"query": { "term": { "status": "pending" } }
}
GET /_cat/indices?v=true&s=store.size:desc
GET /_cat/indices/orders,order_lines?format=json&bytes=mb
GET /orders/_mapping_count gives an exact count. A search's hits.total stops counting at 10,000 unless you set "track_total_hits": true. The _cat APIs are for people: v=true adds headers, s sorts, and format=json returns JSON instead of a text table.
SQL: Elasticsearch _sql and OpenSearch _plugins/_sql
Both engines accept SQL for reads, at different endpoints. Elasticsearch:
POST /_sql?format=txt
{
"query": "SELECT status, COUNT(*) AS orders, SUM(total) AS revenue FROM orders GROUP BY status ORDER BY revenue DESC"
}
POST /_sql/translate
{
"query": "SELECT status, COUNT(*) FROM orders GROUP BY status"
}format can be txt, json, csv and others; _sql/translate shows the query DSL your SQL becomes. Elasticsearch 8.14 and later also have ES|QL, a piped language at POST /_query with a body like {"query": "FROM orders | STATS orders = COUNT(*) BY status"}.
OpenSearch:
POST /_plugins/_sql
{
"query": "SELECT status, COUNT(*) AS orders, SUM(total) AS revenue FROM orders GROUP BY status"
}
POST /_plugins/_sql/_explain
{
"query": "SELECT status, COUNT(*) FROM orders GROUP BY status"
}The response format defaults to jdbc; ?format=csv and ?format=raw also work. OpenSearch's other query language, PPL, is at POST /_plugins/_ppl, for example source=orders | stats count() by status.
Running console requests in Tablux
Tablux on Mac, iPhone and iPad takes the same console syntax for Elasticsearch and OpenSearch: a GET, POST, PUT, DELETE, HEAD or PATCH line, then the JSON body, with # and // comment lines. Several requests run in order. Hits become rows (_id, _index, then the _source fields); with "size": 0, the first bucket aggregation becomes one row per bucket with doc_count and single-value metrics such as sum and avg as columns; _count and _cat/…?format=json come back as tables too. Plain SQL goes to _sql or _plugins/_sql. Deleting an index, a match_all _delete_by_query, _reindex and _close are flagged before they run, and read-only connections refuse anything but reads.
Questions
What is the difference between match and term in Elasticsearch?
match analyzes your search text the same way as the field, so it suits text fields. term looks for the exact value without analysis, so it suits keyword, number, date and boolean fields; on a text field it usually finds nothing.
Where is Dev Tools in Kibana?
Find Dev Tools in the navigation menu, or search for it with the global search bar. Its Console sends requests to the cluster Kibana is connected to.
How do I get more than 10,000 results from Elasticsearch?
from + size stops at 10,000 hits by default. Open a point in time and page with search_after, using the sort values of the last hit.
What is the difference between must and filter in a bool query?
Both must match. must adds to the relevance score; filter doesn't score and can be cached, so use filter for yes/no conditions like status or date ranges.
Do Kibana console queries work in OpenSearch?
Yes. OpenSearch Dashboards has the same Dev Tools console, and the query DSL in this guide works on OpenSearch 2 and 3. Point in time and SQL use different endpoints.
How do I run SQL against Elasticsearch or OpenSearch?
Elasticsearch: POST /_sql?format=txt with {"query": "SELECT …"}. OpenSearch: POST /_plugins/_sql with the same body.
Updated 2026-11-25