Elasticsearch Query DSL Builder
Compose a search request with forms, get JSON for Kibana Dev Tools or curl, check any request body for structural mistakes with line numbers, and turn query strings into bool queries.
S'executa al teu navegador. Els fitxers mai no surten del dispositiu. Mira com comprovar-ho
…
Com es fa
- 1Describe your fields
Paste the mapping JSON or type field: type lines so checks know text from keyword.
- 2Build the query
Add must, filter, should and must_not clauses to the bool tree.
- 3Add aggregations
Choose terms, histograms, ranges or metrics and nest sub-aggregations.
- 4Set the results
Choose size, sort, _source and highlight fields.
- 5Validate
Read the issues tab and fix errors; paste an existing body in validate mode to check it.
- 6Run it
Copy the Dev Tools request or the curl command into your cluster.
Sobre aquesta eina
The Query DSL is the JSON language Elasticsearch and OpenSearch use for searches, and its nesting is easy to get wrong by one bracket or one level. This builder lets you compose the query as a tree. The root is a bool query with four kinds of clause: must clauses have to match and add to the score, filter clauses have to match but do not score and can be cached, should clauses are optional or act as OR, and must_not clauses exclude documents. Each clause can be match, match_phrase, multi_match, term, terms, range, exists, prefix, wildcard, regexp, fuzzy, query_string, ids, a nested bool group or a raw JSON block for anything else. Fields for operator, fuzziness, slop, boost, range bounds and date formats appear only where they apply. Below the query you set size, from, sort, _source and highlight fields, and add aggregations such as terms, date_histogram, histogram, range, filters, percentiles, top_hits and metrics, with sub-aggregations under bucket types. The request is shown as a GET index/_search block for Kibana Dev Tools and as a curl command. You can also tell the tool your field types, either as field: type lines or by pasting the JSON from GET index/_mapping, and the checks then use them.
Structure validation
Paste any search body, with or without the GET line, and the validator reads it with its own JSON parser that remembers the line of every key. JSON mistakes such as trailing commas, single quotes and missing colons are reported with line and column, and duplicate keys are flagged because Elasticsearch refuses them. Unknown top-level keys, unknown query types, a query object with two types, match or term with more than one field, range operators written as >= instead of gte, an empty bool list and from plus size beyond the 10,000 result window are errors or warnings. Aggregations are checked for exactly one type, sub-aggregations under metric types, the removed interval parameter of date_histogram, calendar intervals with more than one unit and pipeline aggregations without buckets_path. With a mapping, term on a text field, terms aggregations on text fields, sorting on text, numeric metrics on keyword fields and date histograms on non-date fields are caught too.
Lucene query strings
Kibana's search bar, the q= parameter and query_string all use the Lucene syntax. The converter parses it with the right precedence and writes the equivalent bool query: field:value, quoted phrases with ~slop, AND, OR, NOT, plus and minus prefixes, parentheses, field:(a OR b), inclusive and exclusive ranges, comparison operators, wildcards, regular expressions, fuzzy terms, boosts and _exists_. Fields you typed as keyword become term queries, text fields become match queries, and the result can be added to the query tree with one tap.
Worked example
Load the log search sample. The request has 83 lines and validates cleanly: a match on message for timeout connection with operator and, a filter on @timestamp from now-24h to now, a terms filter on log.level for error and warn, a must_not term that removes the healthcheck service, a sort on @timestamp descending, an hourly date histogram with the top 5 services in each hour, and 50th, 95th and 99th percentiles of event.duration. The converter turns the sample query string, which asks for service.name checkout with error or warn levels, no health check messages and status codes from 500 to 599, into one bool with three must clauses and one must_not clause. The broken example, checked with the shop mapping, gives 6 errors, 2 warnings and 1 note, starting with from plus size equal to 10010 on line 4.
Limits
The validator checks structure, not your data: it does not connect to a cluster, so it cannot tell whether an index or field exists unless you paste the mapping, and it cannot predict scores or hit counts. Query types it does not model are accepted as valid but not inspected. The Lucene converter does not cover every query_string option, such as analyze_wildcard or field aliases.
Exemple resolt
Log search sample: 83 lines, no issues; Lucene string converts to 3 must clauses and 1 must_not; broken example gives 6 errors with the shop mapping.
En resum
- Categoria: Desenvolupament i dades
- S'executa al navegador, sense registre, sense pujar res.
- La informació que introdueixes es queda al dispositiu.
- Disponible en anglès.
- Contingut revisat per última vegada:
- Font oficial: Elastic Docs: Query DSL
Preguntes freqüents
When should I use filter instead of must?
Use filter for yes or no conditions such as dates, status codes and IDs. Filters do not affect the score and Elasticsearch can cache them, which makes repeated searches faster. Use must when the match should influence ranking.
Why does my term query return nothing?
term looks for the exact stored token. A text field is analysed, so "Wireless Headphones" is stored as two lowercase tokens. Query the keyword sub-field, such as title.keyword, or use match.
How do I get more than 10,000 results?
from plus size cannot pass index.max_result_window, which is 10,000 by default. Page deeper with search_after and a point in time, or use the scroll API for one-off exports.
What is the difference between calendar_interval and fixed_interval?
calendar_interval follows the calendar, so a month or a day in a daylight saving change has its real length; it only accepts one unit such as 1d or 1M. fixed_interval uses exact durations such as 12h or 30m.
Does it work with OpenSearch?
Mostly yes. OpenSearch shares the Query DSL for bool, match, term, range and the common aggregations. Newer Elasticsearch-only features such as retrievers are not built by the form.
Does the tool send my query to a cluster?
No. It only writes and checks JSON in your browser. Copy the request into Kibana Dev Tools or run the curl command yourself.
