- Elasticsearch Guide: other versions:
- Setup
- API Conventions
- Document APIs
- Search APIs
- Indices APIs
- Create Index
- Delete Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Delete Mapping
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Status
- Indices Stats
- Indices Segments
- Clear Cache
- Flush
- Refresh
- Optimize
- Gateway Snapshot
- Cluster APIs
- Query DSL
- Queries
- Match Query
- Multi Match Query
- Bool Query
- Boosting Query
- Common Terms Query
- Custom Filters Score Query
- Custom Score Query
- Custom Boost Factor Query
- Constant Score Query
- Dis Max Query
- Field Query
- Filtered Query
- Fuzzy Like This Query
- Fuzzy Like This Field Query
- Function Score Query
- Fuzzy Query
- GeoShape Query
- Has Child Query
- Has Parent Query
- Ids Query
- Indices Query
- Match All Query
- More Like This Query
- More Like This Field Query
- Nested Query
- Prefix Query
- Query String Query
- Simple Query String Query
- Range Query
- Regexp Query
- Span First Query
- Span Multi Term Query
- Span Near Query
- Span Not Query
- Span Or Query
- Span Term Query
- Term Query
- Terms Query
- Top Children Query
- Wildcard Query
- Text Query
- Minimum Should Match
- Multi Term Query Rewrite
- Filters
- And Filter
- Bool Filter
- Exists Filter
- Geo Bounding Box Filter
- Geo Distance Filter
- Geo Distance Range Filter
- Geo Polygon Filter
- GeoShape Filter
- Geohash Cell Filter
- Has Child Filter
- Has Parent Filter
- Ids Filter
- Indices Filter
- Limit Filter
- Match All Filter
- Missing Filter
- Nested Filter
- Not Filter
- Numeric Range Filter
- Or Filter
- Prefix Filter
- Query Filter
- Range Filter
- Regexp Filter
- Script Filter
- Term Filter
- Terms Filter
- Type Filter
- Queries
- Mapping
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- Keep Words Token Filter
- Delimited Payload Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Glossary of terms
WARNING: Version 0.90 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Text Query
editText Query
edittext
query has been deprecated (effectively renamed) to match
query
since 0.19.9
, please use it. text
is still supported.
A family of text
queries that accept text, analyzes it, and constructs
a query out of it. For example:
{ "text" : { "message" : "this is a test" } }
Note, even though the name is text, it also supports exact matching
(term
like) on numeric values and dates.
Note, message
is the name of a field, you can substitute the name of
any field (including _all
) instead.
Types of Text Queries
editboolean
editThe default text
query is of type boolean
. It means that the text
provided is analyzed and the analysis process constructs a boolean query
from the provided text. The operator
flag can be set to or
or and
to control the boolean clauses (defaults to or
).
The analyzer
can be set to control which analyzer will perform the
analysis process on the text. It default to the field explicit mapping
definition, or the default search analyzer.
fuzziness
can be set to a value (depending on the relevant type, for
string types it should be a value between 0.0
and 1.0
) to constructs
fuzzy queries for each term analyzed. The prefix_length
and
max_expansions
can be set in this case to control the fuzzy process.
Here is an example when providing additional parameters (note the slight
change in structure, message
is the field name):
{ "text" : { "message" : { "query" : "this is a test", "operator" : "and" } } }
phrase
editThe text_phrase
query analyzes the text and creates a phrase
query
out of the analyzed text. For example:
{ "text_phrase" : { "message" : "this is a test" } }
Since text_phrase
is only a type
of a text
query, it can also be
used in the following manner:
{ "text" : { "message" : { "query" : "this is a test", "type" : "phrase" } } }
A phrase query maintains order of the terms up to a configurable slop
(which defaults to 0).
The analyzer
can be set to control which analyzer will perform the
analysis process on the text. It default to the field explicit mapping
definition, or the default search analyzer, for example:
{ "text_phrase" : { "message" : { "query" : "this is a test", "analyzer" : "my_analyzer" } } }
text_phrase_prefix
editThe text_phrase_prefix
is the same as text_phrase
, expect it allows
for prefix matches on the last term in the text. For example:
{ "text_phrase_prefix" : { "message" : "this is a test" } }
Or:
{ "text" : { "message" : { "query" : "this is a test", "type" : "phrase_prefix" } } }
It accepts the same parameters as the phrase type. In addition, it also
accepts a max_expansions
parameter that can control to how many
prefixes the last term will be expanded. It is highly recommended to set
it to an acceptable value to control the execution time of the query.
For example:
{ "text_phrase_prefix" : { "message" : { "query" : "this is a test", "max_expansions" : 10 } } }
Comparison to query_string / field
editThe text family of queries does not go through a "query parsing"
process. It does not support field name prefixes, wildcard characters,
or other "advance" features. For this reason, chances of it failing are
very small / non existent, and it provides an excellent behavior when it
comes to just analyze and run that text as a query behavior (which is
usually what a text search box does). Also, the phrase_prefix
can
provide a great "as you type" behavior to automatically load search
results.