2019-07-17 08:49:22 -04:00
|
|
|
[[completion-suggester]]
|
2019-07-19 14:35:36 -04:00
|
|
|
==== Completion Suggester
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
NOTE: In order to understand the format of suggestions, please
|
2019-03-27 16:29:13 -04:00
|
|
|
read the <<search-suggesters>> page first. For more flexible
|
|
|
|
search-as-you-type searches that do not use suggesters, see the
|
|
|
|
<<search-as-you-type,`search_as_you_type` field type>>.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
The `completion` suggester provides auto-complete/search-as-you-type
|
|
|
|
functionality. This is a navigational feature to guide users to
|
|
|
|
relevant results as they are typing, improving search precision.
|
|
|
|
It is not meant for spell correction or did-you-mean functionality
|
|
|
|
like the `term` or `phrase` suggesters.
|
|
|
|
|
|
|
|
Ideally, auto-complete functionality should be as fast as a user
|
|
|
|
types to provide instant feedback relevant to what a user has already
|
|
|
|
typed in. Hence, `completion` suggester is optimized for speed.
|
|
|
|
The suggester uses data structures that enable fast lookups,
|
|
|
|
but are costly to build and are stored in-memory.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-09-30 17:32:00 -04:00
|
|
|
[[completion-suggester-mapping]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Mapping
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
To use this feature, specify a special mapping for this field,
|
|
|
|
which indexes the field values for fast completions.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT music
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"suggest": {
|
|
|
|
"type": "completion"
|
|
|
|
},
|
|
|
|
"title": {
|
|
|
|
"type": "keyword"
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-08-03 18:40:17 -04:00
|
|
|
// TESTSETUP
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Mapping supports the following parameters:
|
|
|
|
|
2019-02-15 14:39:46 -05:00
|
|
|
[horizontal]
|
2015-01-20 21:15:02 -05:00
|
|
|
`analyzer`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The index analyzer to use, defaults to `simple`.
|
|
|
|
|
2015-01-20 21:15:02 -05:00
|
|
|
`search_analyzer`::
|
|
|
|
The search analyzer to use, defaults to value of `analyzer`.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-09-02 09:55:47 -04:00
|
|
|
`preserve_separators`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Preserves the separators, defaults to `true`.
|
|
|
|
If disabled, you could find a field starting with `Foo Fighters`, if you
|
|
|
|
suggest for `foof`.
|
|
|
|
|
2013-09-04 14:40:36 -04:00
|
|
|
`preserve_position_increments`::
|
2015-10-31 01:59:21 -04:00
|
|
|
Enables position increments, defaults to `true`.
|
|
|
|
If disabled and using stopwords analyzer, you could get a
|
2013-08-28 19:24:34 -04:00
|
|
|
field starting with `The Beatles`, if you suggest for `b`. *Note*: You
|
|
|
|
could also achieve this by indexing two inputs, `Beatles` and
|
|
|
|
`The Beatles`, no need to change a simple analyzer, if you are able to
|
|
|
|
enrich your data.
|
|
|
|
|
2014-01-02 11:11:20 -05:00
|
|
|
`max_input_length`::
|
2013-09-02 09:55:47 -04:00
|
|
|
Limits the length of a single input, defaults to `50` UTF-16 code points.
|
|
|
|
This limit is only used at index time to reduce the total number of
|
|
|
|
characters per input string in order to prevent massive inputs from
|
2019-02-15 14:39:46 -05:00
|
|
|
bloating the underlying datastructure. Most use cases won't be influenced
|
2015-10-31 01:59:21 -04:00
|
|
|
by the default value since prefix completions seldom grow beyond prefixes longer
|
|
|
|
than a handful of characters.
|
2013-09-04 14:40:36 -04:00
|
|
|
|
2013-09-25 12:17:40 -04:00
|
|
|
[[indexing]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Indexing
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
You index suggestions like any other field. A suggestion is made of an
|
|
|
|
`input` and an optional `weight` attribute. An `input` is the expected
|
|
|
|
text to be matched by a suggestion query and the `weight` determines how
|
|
|
|
the suggestions will be scored. Indexing a suggestion is as follows:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT music/_doc/1?refresh
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest" : {
|
|
|
|
"input": [ "Nevermind", "Nirvana" ],
|
|
|
|
"weight" : 34
|
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-08-03 18:40:17 -04:00
|
|
|
// TEST
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The following parameters are supported:
|
|
|
|
|
2019-02-15 14:39:46 -05:00
|
|
|
[horizontal]
|
2013-09-04 14:40:36 -04:00
|
|
|
`input`::
|
2015-12-11 08:38:13 -05:00
|
|
|
The input to store, this can be an array of strings or just
|
2013-08-28 19:24:34 -04:00
|
|
|
a string. This field is mandatory.
|
2019-10-25 10:57:51 -04:00
|
|
|
+
|
2019-10-25 11:30:52 -04:00
|
|
|
[NOTE]
|
|
|
|
====
|
|
|
|
This value cannot contain the following UTF-16 control characters:
|
2019-10-25 10:57:51 -04:00
|
|
|
|
|
|
|
* `\u0000` (null)
|
|
|
|
* `\u001f` (information separator one)
|
|
|
|
* `\u001e` (information separator two)
|
2019-10-25 11:30:52 -04:00
|
|
|
====
|
2019-10-25 10:57:51 -04:00
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-09-04 14:40:36 -04:00
|
|
|
`weight`::
|
2014-10-22 13:44:33 -04:00
|
|
|
A positive integer or a string containing a positive integer,
|
|
|
|
which defines a weight and allows you to rank your suggestions.
|
|
|
|
This field is optional.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
You can index multiple suggestions for a document as follows:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT music/_doc/1?refresh
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest": [
|
|
|
|
{
|
|
|
|
"input": "Nevermind",
|
|
|
|
"weight": 10
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"input": "Nirvana",
|
|
|
|
"weight": 3
|
|
|
|
}
|
|
|
|
]
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-08-03 18:40:17 -04:00
|
|
|
// TEST[continued]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
You can use the following shorthand form. Note that you can not specify
|
2017-05-05 11:33:32 -04:00
|
|
|
a weight with suggestion(s) in the shorthand form.
|
2015-10-31 01:59:21 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2015-10-31 01:59:21 -04:00
|
|
|
--------------------------------------------------
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT music/_doc/1?refresh
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
|
|
|
"suggest" : [ "Nevermind", "Nirvana" ]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-08-03 18:40:17 -04:00
|
|
|
// TEST[continued]
|
2013-11-28 04:27:31 -05:00
|
|
|
|
2013-09-25 12:17:40 -04:00
|
|
|
[[querying]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Querying
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Suggesting works as usual, except that you have to specify the suggest
|
2015-10-31 01:59:21 -04:00
|
|
|
type as `completion`. Suggestions are near real-time, which means
|
|
|
|
new suggestions can be made visible by <<indices-refresh,refresh>> and
|
2016-08-03 18:40:17 -04:00
|
|
|
documents once deleted are never shown. This request:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-12-14 21:49:53 -05:00
|
|
|
POST music/_search?pretty
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest": {
|
|
|
|
"song-suggest": {
|
|
|
|
"prefix": "nir", <1>
|
|
|
|
"completion": { <2>
|
|
|
|
"field": "suggest" <3>
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
2016-08-03 18:40:17 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2017-09-13 11:28:31 -04:00
|
|
|
<1> Prefix used to search for suggestions
|
|
|
|
<2> Type of suggestions
|
|
|
|
<3> Name of the field to search for suggestions in
|
|
|
|
|
2016-08-03 18:40:17 -04:00
|
|
|
returns this response:
|
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console-result]
|
2016-08-03 18:40:17 -04:00
|
|
|
--------------------------------------------------
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
|
|
|
"_shards" : {
|
2018-05-14 12:22:35 -04:00
|
|
|
"total" : 1,
|
|
|
|
"successful" : 1,
|
2017-07-12 16:19:20 -04:00
|
|
|
"skipped" : 0,
|
2013-08-28 19:24:34 -04:00
|
|
|
"failed" : 0
|
|
|
|
},
|
2016-12-14 21:49:53 -05:00
|
|
|
"hits": ...
|
|
|
|
"took": 2,
|
|
|
|
"timed_out": false,
|
|
|
|
"suggest": {
|
|
|
|
"song-suggest" : [ {
|
|
|
|
"text" : "nir",
|
|
|
|
"offset" : 0,
|
|
|
|
"length" : 3,
|
|
|
|
"options" : [ {
|
|
|
|
"text" : "Nirvana",
|
|
|
|
"_index": "music",
|
2017-12-14 11:47:53 -05:00
|
|
|
"_type": "_doc",
|
2016-12-14 21:49:53 -05:00
|
|
|
"_id": "1",
|
|
|
|
"_score": 1.0,
|
|
|
|
"_source": {
|
|
|
|
"suggest": ["Nevermind", "Nirvana"]
|
|
|
|
}
|
|
|
|
} ]
|
2013-08-28 19:24:34 -04:00
|
|
|
} ]
|
2016-12-14 21:49:53 -05:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-12-14 21:49:53 -05:00
|
|
|
// TESTRESPONSE[s/"hits": .../"hits": "$body.hits",/]
|
|
|
|
// TESTRESPONSE[s/"took": 2,/"took": "$body.took",/]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-09-02 12:32:55 -04:00
|
|
|
|
2020-08-05 14:04:55 -04:00
|
|
|
IMPORTANT: `_source` metadata field must be enabled, which is the default
|
2016-09-02 12:32:55 -04:00
|
|
|
behavior, to enable returning `_source` with suggestions.
|
|
|
|
|
|
|
|
The configured weight for a suggestion is returned as `_score`. The
|
|
|
|
`text` field uses the `input` of your indexed suggestion. Suggestions
|
|
|
|
return the full document `_source` by default. The size of the `_source`
|
|
|
|
can impact performance due to disk fetch and network transport overhead.
|
2016-11-06 20:15:45 -05:00
|
|
|
To save some network overhead, filter out unnecessary fields from the `_source`
|
2020-06-11 11:25:04 -04:00
|
|
|
using <<source-filtering, source filtering>> to minimize
|
2016-11-06 20:15:45 -05:00
|
|
|
`_source` size. Note that the _suggest endpoint doesn't support source
|
|
|
|
filtering but using suggest on the `_search` endpoint does:
|
2016-09-02 12:32:55 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2016-09-02 12:32:55 -04:00
|
|
|
--------------------------------------------------
|
2017-09-13 11:28:31 -04:00
|
|
|
POST music/_search
|
2016-09-02 12:32:55 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"_source": "suggest", <1>
|
|
|
|
"suggest": {
|
|
|
|
"song-suggest": {
|
|
|
|
"prefix": "nir",
|
|
|
|
"completion": {
|
|
|
|
"field": "suggest", <2>
|
|
|
|
"size": 5 <3>
|
|
|
|
}
|
2016-09-02 12:32:55 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2016-09-02 12:32:55 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-11-06 20:15:45 -05:00
|
|
|
// TEST[continued]
|
|
|
|
|
2017-09-13 11:28:31 -04:00
|
|
|
<1> Filter the source to return only the `suggest` field
|
|
|
|
<2> Name of the field to search for suggestions in
|
|
|
|
<3> Number of suggestions to return
|
|
|
|
|
2016-11-06 20:15:45 -05:00
|
|
|
Which should look like:
|
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console-result]
|
2016-11-06 20:15:45 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"took": 6,
|
|
|
|
"timed_out": false,
|
|
|
|
"_shards": {
|
|
|
|
"total": 1,
|
|
|
|
"successful": 1,
|
|
|
|
"skipped": 0,
|
|
|
|
"failed": 0
|
|
|
|
},
|
|
|
|
"hits": {
|
|
|
|
"total": {
|
|
|
|
"value": 0,
|
|
|
|
"relation": "eq"
|
2016-11-06 20:15:45 -05:00
|
|
|
},
|
2020-07-21 15:49:58 -04:00
|
|
|
"max_score": null,
|
|
|
|
"hits": []
|
|
|
|
},
|
|
|
|
"suggest": {
|
|
|
|
"song-suggest": [ {
|
|
|
|
"text": "nir",
|
|
|
|
"offset": 0,
|
|
|
|
"length": 3,
|
|
|
|
"options": [ {
|
|
|
|
"text": "Nirvana",
|
|
|
|
"_index": "music",
|
|
|
|
"_type": "_doc",
|
|
|
|
"_id": "1",
|
|
|
|
"_score": 1.0,
|
|
|
|
"_source": {
|
|
|
|
"suggest": [ "Nevermind", "Nirvana" ]
|
|
|
|
}
|
|
|
|
} ]
|
|
|
|
} ]
|
|
|
|
}
|
2016-11-06 20:15:45 -05:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TESTRESPONSE[s/"took": 6,/"took": $body.took,/]
|
2015-10-31 01:59:21 -04:00
|
|
|
|
|
|
|
The basic completion suggester query supports the following parameters:
|
2014-10-14 12:46:57 -04:00
|
|
|
|
2019-02-15 14:39:46 -05:00
|
|
|
[horizontal]
|
2014-10-14 12:46:57 -04:00
|
|
|
`field`:: The name of the field on which to run the query (required).
|
|
|
|
`size`:: The number of suggestions to return (defaults to `5`).
|
2017-09-07 11:11:01 -04:00
|
|
|
`skip_duplicates`:: Whether duplicate suggestions should be filtered out (defaults to `false`).
|
2014-10-14 12:46:57 -04:00
|
|
|
|
2013-10-08 07:55:25 -04:00
|
|
|
NOTE: The completion suggester considers all documents in the index.
|
2019-07-19 09:16:35 -04:00
|
|
|
See <<context-suggester>> for an explanation of how to query a subset of
|
2013-10-08 07:55:25 -04:00
|
|
|
documents instead.
|
2013-09-04 14:40:36 -04:00
|
|
|
|
2016-09-02 12:32:55 -04:00
|
|
|
NOTE: In case of completion queries spanning more than one shard, the suggest
|
|
|
|
is executed in two phases, where the last phase fetches the relevant documents
|
|
|
|
from shards, implying executing completion requests against a single shard is
|
|
|
|
more performant due to the document fetch overhead when the suggest spans
|
|
|
|
multiple shards. To get best performance for completions, it is recommended to
|
|
|
|
index completions into a single shard index. In case of high heap usage due to
|
|
|
|
shard size, it is still recommended to break index into multiple shards instead
|
|
|
|
of optimizing for completion performance.
|
2015-10-31 01:59:21 -04:00
|
|
|
|
2017-09-07 11:11:01 -04:00
|
|
|
[[skip_duplicates]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Skip duplicate suggestions
|
2017-09-07 11:11:01 -04:00
|
|
|
|
|
|
|
Queries can return duplicate suggestions coming from different documents.
|
|
|
|
It is possible to modify this behavior by setting `skip_duplicates` to true.
|
|
|
|
When set, this option filters out documents with duplicate suggestions from the result.
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2017-09-07 11:11:01 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
POST music/_search?pretty
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest": {
|
|
|
|
"song-suggest": {
|
|
|
|
"prefix": "nor",
|
|
|
|
"completion": {
|
|
|
|
"field": "suggest",
|
|
|
|
"skip_duplicates": true
|
|
|
|
}
|
2017-09-07 11:11:01 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2017-09-07 11:11:01 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2019-02-15 14:39:46 -05:00
|
|
|
WARNING: When set to true, this option can slow down search because more suggestions
|
2017-09-07 11:11:01 -04:00
|
|
|
need to be visited to find the top N.
|
|
|
|
|
2013-09-25 12:17:40 -04:00
|
|
|
[[fuzzy]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Fuzzy queries
|
2013-09-04 14:40:36 -04:00
|
|
|
|
2019-02-15 14:39:46 -05:00
|
|
|
The completion suggester also supports fuzzy queries -- this means
|
2015-10-31 01:59:21 -04:00
|
|
|
you can have a typo in your search and still get results back.
|
2013-09-04 14:40:36 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-09-04 14:40:36 -04:00
|
|
|
--------------------------------------------------
|
2016-12-14 21:49:53 -05:00
|
|
|
POST music/_search?pretty
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest": {
|
|
|
|
"song-suggest": {
|
|
|
|
"prefix": "nor",
|
|
|
|
"completion": {
|
|
|
|
"field": "suggest",
|
|
|
|
"fuzzy": {
|
|
|
|
"fuzziness": 2
|
2013-09-04 14:40:36 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-09-04 14:40:36 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
2013-09-04 14:40:36 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
|
2015-10-31 01:59:21 -04:00
|
|
|
Suggestions that share the longest prefix to the query `prefix` will
|
|
|
|
be scored higher.
|
|
|
|
|
2013-09-04 14:40:36 -04:00
|
|
|
The fuzzy query can take specific fuzzy parameters.
|
|
|
|
The following parameters are supported:
|
|
|
|
|
|
|
|
[horizontal]
|
2014-01-02 10:45:24 -05:00
|
|
|
`fuzziness`::
|
|
|
|
The fuzziness factor, defaults to `AUTO`.
|
|
|
|
See <<fuzziness>> for allowed settings.
|
2013-09-04 14:40:36 -04:00
|
|
|
|
|
|
|
`transpositions`::
|
2015-07-14 22:37:44 -04:00
|
|
|
if set to `true`, transpositions are counted
|
|
|
|
as one change instead of two, defaults to `true`
|
2013-09-04 14:40:36 -04:00
|
|
|
|
|
|
|
`min_length`::
|
|
|
|
Minimum length of the input before fuzzy
|
|
|
|
suggestions are returned, defaults `3`
|
|
|
|
|
|
|
|
`prefix_length`::
|
|
|
|
Minimum length of the input, which is not
|
|
|
|
checked for fuzzy alternatives, defaults to `1`
|
|
|
|
|
2013-11-25 12:22:34 -05:00
|
|
|
`unicode_aware`::
|
2015-10-31 01:59:21 -04:00
|
|
|
If `true`, all measurements (like fuzzy edit
|
|
|
|
distance, transpositions, and lengths) are
|
|
|
|
measured in Unicode code points instead of
|
|
|
|
in bytes. This is slightly slower than raw
|
|
|
|
bytes, so it is set to `false` by default.
|
2013-11-25 12:22:34 -05:00
|
|
|
|
2013-09-04 14:40:36 -04:00
|
|
|
NOTE: If you want to stick with the default values, but
|
|
|
|
still use fuzzy, you can either use `fuzzy: {}`
|
|
|
|
or `fuzzy: true`.
|
2015-10-31 01:59:21 -04:00
|
|
|
|
|
|
|
[[regex]]
|
2019-07-19 14:35:36 -04:00
|
|
|
===== Regex queries
|
2015-10-31 01:59:21 -04:00
|
|
|
|
|
|
|
The completion suggester also supports regex queries meaning
|
|
|
|
you can express a prefix as a regular expression
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2015-10-31 01:59:21 -04:00
|
|
|
--------------------------------------------------
|
2016-12-14 21:49:53 -05:00
|
|
|
POST music/_search?pretty
|
2015-10-31 01:59:21 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"suggest": {
|
|
|
|
"song-suggest": {
|
|
|
|
"regex": "n[ever|i]r",
|
|
|
|
"completion": {
|
|
|
|
"field": "suggest"
|
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-10-31 01:59:21 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
The regex query can take specific regex parameters.
|
|
|
|
The following parameters are supported:
|
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`flags`::
|
|
|
|
Possible flags are `ALL` (default), `ANYSTRING`, `COMPLEMENT`,
|
|
|
|
`EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. See <<query-dsl-regexp-query, regexp-syntax>>
|
|
|
|
for their meaning
|
|
|
|
|
|
|
|
`max_determinized_states`::
|
|
|
|
Regular expressions are dangerous because it's easy to accidentally
|
|
|
|
create an innocuous looking one that requires an exponential number of
|
|
|
|
internal determinized automaton states (and corresponding RAM and CPU)
|
|
|
|
for Lucene to execute. Lucene prevents these using the
|
|
|
|
`max_determinized_states` setting (defaults to 10000). You can raise
|
|
|
|
this limit to allow more complex regular expressions to execute.
|