2013-08-29 07:24:34 +08:00
|
|
|
[[query-dsl]]
|
|
|
|
= Query DSL
|
|
|
|
|
|
|
|
[partintro]
|
|
|
|
--
|
|
|
|
|
2017-12-12 01:05:39 +08:00
|
|
|
Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries.
|
|
|
|
Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of
|
2015-06-04 07:59:22 +08:00
|
|
|
clauses:
|
|
|
|
|
|
|
|
Leaf query clauses::
|
|
|
|
|
|
|
|
Leaf query clauses look for a particular value in a particular field, such as the
|
|
|
|
<<query-dsl-match-query,`match`>>, <<query-dsl-term-query,`term`>> or
|
2021-03-31 21:57:47 +08:00
|
|
|
<<query-dsl-range-query,`range`>> queries. These queries can be used
|
2015-06-04 07:59:22 +08:00
|
|
|
by themselves.
|
|
|
|
|
|
|
|
Compound query clauses::
|
|
|
|
|
|
|
|
Compound query clauses wrap other leaf *or* compound queries and are used to combine
|
|
|
|
multiple queries in a logical fashion (such as the
|
|
|
|
<<query-dsl-bool-query,`bool`>> or <<query-dsl-dis-max-query,`dis_max`>> query),
|
2015-10-21 03:53:41 +08:00
|
|
|
or to alter their behaviour (such as the
|
2015-06-04 07:59:22 +08:00
|
|
|
<<query-dsl-constant-score-query,`constant_score`>> query).
|
|
|
|
|
|
|
|
Query clauses behave differently depending on whether they are used in
|
|
|
|
<<query-filter-context,query context or filter context>>.
|
2020-02-13 01:06:04 +08:00
|
|
|
|
|
|
|
[[query-dsl-allow-expensive-queries]]
|
|
|
|
Allow expensive queries::
|
|
|
|
Certain types of queries will generally execute slowly due to the way they are implemented, which can affect
|
|
|
|
the stability of the cluster. Those queries can be categorised as follows:
|
2021-04-20 23:47:29 +08:00
|
|
|
|
2020-02-13 01:06:04 +08:00
|
|
|
* Queries that need to do linear scans to identify matches:
|
2021-04-20 23:47:29 +08:00
|
|
|
** <<query-dsl-script-query,`script` queries>>
|
Allow docvalues-only search on number types (#82409)
Allows searching on number field types (long, short, int, float, double, byte, half_float) when those fields are not
indexed (index: false) but just doc values are enabled.
This enables searches on archive data, which has access to doc values but not index structures. When combined with
searchable snapshots, it allows downloading only data for a given (doc value) field to quickly filter down to a select set
of documents.
Note to reviewers:
I have split isSearchable into two separate methods isIndexed and isSearchable on MappedFieldType. The former one is
about whether actual indexing data structures have been used (postings or points), and the latter one on whether you
can run queries on the given field (e.g. used by field caps). For number field types, queries are now allowed whenever
points are available or when doc values are available (i.e. searchability is expanded).
Relates #81210 and #52728
2022-01-13 23:23:01 +08:00
|
|
|
** queries on <<number,numeric fields>> that are not indexed but have <<doc-values,doc values>> enabled
|
2021-04-20 23:47:29 +08:00
|
|
|
|
|
|
|
* Queries that have a high up-front cost:
|
|
|
|
** <<query-dsl-fuzzy-query,`fuzzy` queries>> (except on
|
|
|
|
<<wildcard-field-type,`wildcard`>> fields)
|
|
|
|
** <<query-dsl-regexp-query,`regexp` queries>> (except on
|
|
|
|
<<wildcard-field-type,`wildcard`>> fields)
|
|
|
|
** <<query-dsl-prefix-query,`prefix` queries>> (except on
|
|
|
|
<<wildcard-field-type,`wildcard`>> fields or those without
|
|
|
|
<<index-prefixes,`index_prefixes`>>)
|
|
|
|
** <<query-dsl-wildcard-query,`wildcard` queries>> (except on
|
|
|
|
<<wildcard-field-type,`wildcard`>> fields)
|
|
|
|
** <<query-dsl-range-query,`range` queries>> on <<text,`text`>> and
|
|
|
|
<<keyword,`keyword`>> fields
|
|
|
|
|
|
|
|
* <<joining-queries,Joining queries>>
|
|
|
|
|
2020-02-13 01:06:04 +08:00
|
|
|
* Queries that may have a high per-document cost:
|
2021-04-20 23:47:29 +08:00
|
|
|
** <<query-dsl-script-score-query,`script_score` queries>>
|
|
|
|
** <<query-dsl-percolate-query,`percolate` queries>>
|
2020-02-13 01:06:04 +08:00
|
|
|
|
|
|
|
The execution of such queries can be prevented by setting the value of the `search.allow_expensive_queries`
|
|
|
|
setting to `false` (defaults to `true`).
|
2013-08-29 07:24:34 +08:00
|
|
|
--
|
|
|
|
|
2015-06-04 07:59:22 +08:00
|
|
|
include::query-dsl/query_filter_context.asciidoc[]
|
|
|
|
|
2019-07-18 22:18:11 +08:00
|
|
|
include::query-dsl/compound-queries.asciidoc[]
|
2015-06-04 07:59:22 +08:00
|
|
|
|
|
|
|
include::query-dsl/full-text-queries.asciidoc[]
|
|
|
|
|
2019-07-18 22:18:11 +08:00
|
|
|
include::query-dsl/geo-queries.asciidoc[]
|
2015-06-04 07:59:22 +08:00
|
|
|
|
2019-08-09 04:28:35 +08:00
|
|
|
include::query-dsl/shape-queries.asciidoc[]
|
|
|
|
|
2015-06-04 07:59:22 +08:00
|
|
|
include::query-dsl/joining-queries.asciidoc[]
|
|
|
|
|
2019-07-18 22:18:11 +08:00
|
|
|
include::query-dsl/match-all-query.asciidoc[]
|
|
|
|
|
|
|
|
include::query-dsl/span-queries.asciidoc[]
|
2015-06-04 07:59:22 +08:00
|
|
|
|
|
|
|
include::query-dsl/special-queries.asciidoc[]
|
|
|
|
|
2019-07-18 22:18:11 +08:00
|
|
|
include::query-dsl/term-level-queries.asciidoc[]
|
2015-06-04 07:59:22 +08:00
|
|
|
|
|
|
|
include::query-dsl/minimum-should-match.asciidoc[]
|
|
|
|
|
2019-07-24 20:37:37 +08:00
|
|
|
include::query-dsl/multi-term-rewrite.asciidoc[]
|
|
|
|
|
2020-02-13 01:06:04 +08:00
|
|
|
include::query-dsl/regexp-syntax.asciidoc[]
|