2013-08-28 19:24:34 -04:00
|
|
|
[[search-suggesters-phrase]]
|
|
|
|
=== Phrase Suggester
|
|
|
|
|
|
|
|
NOTE: In order to understand the format of suggestions, please
|
|
|
|
read the <<search-suggesters>> page first.
|
|
|
|
|
|
|
|
The `term` suggester provides a very convenient API to access word
|
2014-03-27 19:27:16 -04:00
|
|
|
alternatives on a per token basis within a certain string distance. The API
|
2013-08-28 19:24:34 -04:00
|
|
|
allows accessing each token in the stream individually while
|
|
|
|
suggest-selection is left to the API consumer. Yet, often pre-selected
|
|
|
|
suggestions are required in order to present to the end-user. The
|
|
|
|
`phrase` suggester adds additional logic on top of the `term` suggester
|
|
|
|
to select entire corrected phrases instead of individual tokens weighted
|
2014-08-13 15:13:53 -04:00
|
|
|
based on `ngram-language` models. In practice this suggester will be
|
2014-03-28 12:09:56 -04:00
|
|
|
able to make better decisions about which tokens to pick based on
|
2014-11-02 18:36:06 -05:00
|
|
|
co-occurrence and frequencies.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
==== API Example
|
|
|
|
|
2016-07-22 18:51:36 -04:00
|
|
|
In general the `phrase` suggester requires special mapping up front to work.
|
|
|
|
The `phrase` suggester examples on this page need the following mapping to
|
|
|
|
work. The `reverse` analyzer is used only in the last example.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT test
|
2016-07-22 18:51:36 -04:00
|
|
|
{
|
|
|
|
"settings": {
|
|
|
|
"index": {
|
|
|
|
"number_of_shards": 1,
|
|
|
|
"analysis": {
|
|
|
|
"analyzer": {
|
|
|
|
"trigram": {
|
|
|
|
"type": "custom",
|
|
|
|
"tokenizer": "standard",
|
2018-09-06 08:42:06 -04:00
|
|
|
"filter": ["shingle"]
|
2016-07-22 18:51:36 -04:00
|
|
|
},
|
|
|
|
"reverse": {
|
|
|
|
"type": "custom",
|
|
|
|
"tokenizer": "standard",
|
2018-09-06 08:42:06 -04:00
|
|
|
"filter": ["reverse"]
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"filter": {
|
|
|
|
"shingle": {
|
|
|
|
"type": "shingle",
|
|
|
|
"min_shingle_size": 2,
|
|
|
|
"max_shingle_size": 3
|
|
|
|
}
|
2013-09-04 14:24:37 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
2016-07-22 18:51:36 -04:00
|
|
|
},
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"title": {
|
|
|
|
"type": "text",
|
|
|
|
"fields": {
|
|
|
|
"trigram": {
|
|
|
|
"type": "text",
|
|
|
|
"analyzer": "trigram"
|
|
|
|
},
|
|
|
|
"reverse": {
|
|
|
|
"type": "text",
|
|
|
|
"analyzer": "reverse"
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 14:54:04 -04:00
|
|
|
POST test/_doc?refresh=true
|
2016-07-22 18:51:36 -04:00
|
|
|
{"title": "noble warriors"}
|
2018-10-22 14:54:04 -04:00
|
|
|
POST test/_doc?refresh=true
|
2016-07-22 18:51:36 -04:00
|
|
|
{"title": "nobel prize"}
|
|
|
|
--------------------------------------------------
|
2016-09-06 10:46:50 -04:00
|
|
|
// CONSOLE
|
2016-07-22 18:51:36 -04:00
|
|
|
// TESTSETUP
|
|
|
|
|
|
|
|
Once you have the analyzers and mappings set up you can use the `phrase`
|
|
|
|
suggester in the same spot you'd use the `term` suggester:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-12-14 21:49:53 -05:00
|
|
|
POST test/_search
|
2016-07-22 18:51:36 -04:00
|
|
|
{
|
2016-12-14 21:49:53 -05:00
|
|
|
"suggest": {
|
|
|
|
"text": "noble prize",
|
|
|
|
"simple_phrase": {
|
|
|
|
"phrase": {
|
2016-07-22 18:51:36 -04:00
|
|
|
"field": "title.trigram",
|
2016-12-14 21:49:53 -05:00
|
|
|
"size": 1,
|
|
|
|
"gram_size": 3,
|
|
|
|
"direct_generator": [ {
|
|
|
|
"field": "title.trigram",
|
|
|
|
"suggest_mode": "always"
|
|
|
|
} ],
|
|
|
|
"highlight": {
|
|
|
|
"pre_tag": "<em>",
|
|
|
|
"post_tag": "</em>"
|
|
|
|
}
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-07-22 18:51:36 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-11-18 06:05:49 -05:00
|
|
|
The response contains suggestions scored by the most likely spell correction first. In this case we received the expected correction "nobel prize".
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-07-22 18:51:36 -04:00
|
|
|
{
|
|
|
|
"_shards": ...
|
2016-12-14 21:49:53 -05:00
|
|
|
"hits": ...
|
|
|
|
"timed_out": false,
|
|
|
|
"took": 3,
|
|
|
|
"suggest": {
|
|
|
|
"simple_phrase" : [
|
|
|
|
{
|
|
|
|
"text" : "noble prize",
|
|
|
|
"offset" : 0,
|
|
|
|
"length" : 11,
|
|
|
|
"options" : [ {
|
|
|
|
"text" : "nobel prize",
|
|
|
|
"highlighted": "<em>nobel</em> prize",
|
2017-10-31 08:08:44 -04:00
|
|
|
"score" : 0.48614594
|
2016-12-14 21:49:53 -05:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-07-22 18:51:36 -04:00
|
|
|
// TESTRESPONSE[s/"_shards": .../"_shards": "$body._shards",/]
|
2016-12-14 21:49:53 -05:00
|
|
|
// TESTRESPONSE[s/"hits": .../"hits": "$body.hits",/]
|
|
|
|
// TESTRESPONSE[s/"took": 3,/"took": "$body.took",/]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
==== Basic Phrase suggest API parameters
|
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`field`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The name of the field used to do n-gram lookups for the
|
2013-08-28 19:24:34 -04:00
|
|
|
language model, the suggester will use this field to gain statistics to
|
|
|
|
score corrections. This field is mandatory.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`gram_size`::
|
2019-02-20 04:36:37 -05:00
|
|
|
Sets max size of the n-grams (shingles) in the `field`.
|
|
|
|
If the field doesn't contain n-grams (shingles), this should be omitted
|
2013-08-28 19:24:34 -04:00
|
|
|
or set to `1`. Note that Elasticsearch tries to detect the gram size
|
2019-02-20 04:36:37 -05:00
|
|
|
based on the specified `field`. If the field uses a `shingle` filter, the
|
2013-08-28 19:24:34 -04:00
|
|
|
`gram_size` is set to the `max_shingle_size` if not explicitly set.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`real_word_error_likelihood`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The likelihood of a term being a
|
2014-11-20 13:46:31 -05:00
|
|
|
misspelled even if the term exists in the dictionary. The default is
|
2019-02-20 04:36:37 -05:00
|
|
|
`0.95`, meaning 5% of the real words are misspelled.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`confidence`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The confidence level defines a factor applied to the
|
|
|
|
input phrases score which is used as a threshold for other suggest
|
|
|
|
candidates. Only candidates that score higher than the threshold will be
|
|
|
|
included in the result. For instance a confidence level of `1.0` will
|
|
|
|
only return suggestions that score higher than the input phrase. If set
|
|
|
|
to `0.0` the top N candidates are returned. The default is `1.0`.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`max_errors`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The maximum percentage of the terms
|
2013-08-28 19:24:34 -04:00
|
|
|
considered to be misspellings in order to form a correction. This method
|
|
|
|
accepts a float value in the range `[0..1)` as a fraction of the actual
|
2015-09-22 09:31:17 -04:00
|
|
|
query terms or a number `>=1` as an absolute number of query terms. The
|
2019-02-20 04:36:37 -05:00
|
|
|
default is set to `1.0`, meaning only corrections with
|
|
|
|
at most one misspelled term are returned. Note that setting this too high
|
|
|
|
can negatively impact performance. Low values like `1` or `2` are recommended;
|
2016-01-04 14:48:56 -05:00
|
|
|
otherwise the time spend in suggest calls might exceed the time spend in
|
2014-01-08 12:59:43 -05:00
|
|
|
query execution.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`separator`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The separator that is used to separate terms in the
|
2013-08-28 19:24:34 -04:00
|
|
|
bigram field. If not set the whitespace character is used as a
|
|
|
|
separator.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`size`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The number of candidates that are generated for each
|
|
|
|
individual query term. Low numbers like `3` or `5` typically produce good
|
2013-08-28 19:24:34 -04:00
|
|
|
results. Raising this can bring up terms with higher edit distances. The
|
|
|
|
default is `5`.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`analyzer`::
|
2019-02-20 04:36:37 -05:00
|
|
|
Sets the analyzer to analyze to suggest text with.
|
2013-08-28 19:24:34 -04:00
|
|
|
Defaults to the search analyzer of the suggest field passed via `field`.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`shard_size`::
|
2019-02-20 04:36:37 -05:00
|
|
|
Sets the maximum number of suggested terms to be
|
2013-08-28 19:24:34 -04:00
|
|
|
retrieved from each individual shard. During the reduce phase, only the
|
|
|
|
top N suggestions are returned based on the `size` option. Defaults to
|
|
|
|
`5`.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`text`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Sets the text / query to provide suggestions for.
|
|
|
|
|
2013-09-04 14:24:37 -04:00
|
|
|
`highlight`::
|
2016-01-04 14:48:56 -05:00
|
|
|
Sets up suggestion highlighting. If not provided then
|
|
|
|
no `highlighted` field is returned. If provided must
|
2019-02-20 04:36:37 -05:00
|
|
|
contain exactly `pre_tag` and `post_tag`, which are
|
2016-01-04 14:48:56 -05:00
|
|
|
wrapped around the changed tokens. If multiple tokens
|
|
|
|
in a row are changed the entire phrase of changed tokens
|
2013-09-04 14:24:37 -04:00
|
|
|
is wrapped rather than each token.
|
|
|
|
|
2014-07-07 15:13:15 -04:00
|
|
|
`collate`::
|
2015-05-15 16:17:47 -04:00
|
|
|
Checks each suggestion against the specified `query` to prune suggestions
|
|
|
|
for which no matching docs exist in the index. The collate query for a
|
|
|
|
suggestion is run only on the local shard from which the suggestion has
|
2017-05-10 06:18:19 -04:00
|
|
|
been generated from. The `query` must be specified and it can be templated,
|
|
|
|
see <<search-template,search templates>> for more information.
|
2015-05-13 15:23:18 -04:00
|
|
|
The current suggestion is automatically made available as the `{{suggestion}}`
|
2015-05-15 16:17:47 -04:00
|
|
|
variable, which should be used in your query. You can still specify
|
2015-05-13 15:23:18 -04:00
|
|
|
your own template `params` -- the `suggestion` value will be added to the
|
|
|
|
variables you specify. Additionally, you can specify a `prune` to control
|
2019-02-20 04:36:37 -05:00
|
|
|
if all phrase suggestions will be returned; when set to `true` the suggestions
|
2015-05-13 15:23:18 -04:00
|
|
|
will have an additional option `collate_match`, which will be `true` if
|
|
|
|
matching documents for the phrase was found, `false` otherwise.
|
|
|
|
The default value for `prune` is `false`.
|
2014-07-07 15:13:15 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-06-21 05:15:51 -04:00
|
|
|
POST test/_search
|
2016-07-22 18:51:36 -04:00
|
|
|
{
|
2016-12-14 21:49:53 -05:00
|
|
|
"suggest": {
|
|
|
|
"text" : "noble prize",
|
|
|
|
"simple_phrase" : {
|
|
|
|
"phrase" : {
|
|
|
|
"field" : "title.trigram",
|
|
|
|
"size" : 1,
|
|
|
|
"direct_generator" : [ {
|
|
|
|
"field" : "title.trigram",
|
|
|
|
"suggest_mode" : "always",
|
|
|
|
"min_word_length" : 1
|
|
|
|
} ],
|
|
|
|
"collate": {
|
|
|
|
"query": { <1>
|
2017-06-09 11:29:25 -04:00
|
|
|
"source" : {
|
2016-12-14 21:49:53 -05:00
|
|
|
"match": {
|
|
|
|
"{{field_name}}" : "{{suggestion}}" <2>
|
|
|
|
}
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
2016-12-14 21:49:53 -05:00
|
|
|
},
|
|
|
|
"params": {"field_name" : "title"}, <3>
|
|
|
|
"prune": true <4>
|
|
|
|
}
|
2016-07-22 18:51:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 15:13:15 -04:00
|
|
|
--------------------------------------------------
|
2016-07-22 18:51:36 -04:00
|
|
|
// CONSOLE
|
2014-07-07 15:13:15 -04:00
|
|
|
<1> This query will be run once for every suggestion.
|
|
|
|
<2> The `{{suggestion}}` variable will be replaced by the text
|
|
|
|
of each suggestion.
|
|
|
|
<3> An additional `field_name` variable has been specified in
|
|
|
|
`params` and is used by the `match` query.
|
2015-05-13 15:23:18 -04:00
|
|
|
<4> All suggestions will be returned with an extra `collate_match`
|
2014-07-18 19:16:31 -04:00
|
|
|
option indicating whether the generated phrase matched any
|
|
|
|
document.
|
2014-07-07 15:13:15 -04:00
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
==== Smoothing Models
|
|
|
|
|
|
|
|
The `phrase` suggester supports multiple smoothing models to balance
|
|
|
|
weight between infrequent grams (grams (shingles) are not existing in
|
2019-06-11 04:13:03 -04:00
|
|
|
the index) and frequent grams (appear at least once in the index). The
|
|
|
|
smoothing model can be selected by setting the `smoothing` parameter
|
|
|
|
to one of the following options. Each smoothing model supports specific
|
|
|
|
properties that can be configured.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[horizontal]
|
2016-01-04 14:48:56 -05:00
|
|
|
`stupid_backoff`::
|
2019-02-20 04:36:37 -05:00
|
|
|
A simple backoff model that backs off to lower
|
2013-08-28 19:24:34 -04:00
|
|
|
order n-gram models if the higher order count is `0` and discounts the
|
|
|
|
lower order n-gram model by a constant factor. The default `discount` is
|
2016-01-04 14:48:56 -05:00
|
|
|
`0.4`. Stupid Backoff is the default model.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
`laplace`::
|
2019-02-20 04:36:37 -05:00
|
|
|
A smoothing model that uses an additive smoothing where a
|
2013-08-28 19:24:34 -04:00
|
|
|
constant (typically `1.0` or smaller) is added to all counts to balance
|
2019-02-20 04:36:37 -05:00
|
|
|
weights. The default `alpha` is `0.5`.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`linear_interpolation`::
|
2019-02-20 04:36:37 -05:00
|
|
|
A smoothing model that takes the weighted
|
|
|
|
mean of the unigrams, bigrams, and trigrams based on user supplied
|
2013-08-28 19:24:34 -04:00
|
|
|
weights (lambdas). Linear Interpolation doesn't have any default values.
|
|
|
|
All parameters (`trigram_lambda`, `bigram_lambda`, `unigram_lambda`)
|
|
|
|
must be supplied.
|
|
|
|
|
2019-06-11 04:13:03 -04:00
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-06-21 05:15:51 -04:00
|
|
|
POST test/_search
|
2019-06-11 04:13:03 -04:00
|
|
|
{
|
|
|
|
"suggest": {
|
|
|
|
"text" : "obel prize",
|
|
|
|
"simple_phrase" : {
|
|
|
|
"phrase" : {
|
|
|
|
"field" : "title.trigram",
|
|
|
|
"size" : 1,
|
|
|
|
"smoothing" : {
|
|
|
|
"laplace" : {
|
|
|
|
"alpha" : 0.7
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// CONSOLE
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
==== Candidate Generators
|
|
|
|
|
|
|
|
The `phrase` suggester uses candidate generators to produce a list of
|
|
|
|
possible terms per term in the given text. A single candidate generator
|
|
|
|
is similar to a `term` suggester called for each individual term in the
|
|
|
|
text. The output of the generators is subsequently scored in combination
|
2019-02-20 04:36:37 -05:00
|
|
|
with the candidates from the other terms for suggestion candidates.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Currently only one type of candidate generator is supported, the
|
|
|
|
`direct_generator`. The Phrase suggest API accepts a list of generators
|
2019-02-20 04:36:37 -05:00
|
|
|
under the key `direct_generator`; each of the generators in the list is
|
2013-08-28 19:24:34 -04:00
|
|
|
called per term in the original text.
|
|
|
|
|
|
|
|
==== Direct Generators
|
|
|
|
|
|
|
|
The direct generators support the following parameters:
|
|
|
|
|
|
|
|
[horizontal]
|
2016-01-04 14:48:56 -05:00
|
|
|
`field`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The field to fetch the candidate suggestions from. This is
|
2014-04-30 04:33:41 -04:00
|
|
|
a required option that either needs to be set globally or per
|
2013-08-28 19:24:34 -04:00
|
|
|
suggestion.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`size`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The maximum corrections to be returned per suggest text token.
|
|
|
|
|
|
|
|
`suggest_mode`::
|
2016-01-04 14:48:56 -05:00
|
|
|
The suggest mode controls what suggestions are included on the suggestions
|
|
|
|
generated on each shard. All values other than `always` can be thought of
|
|
|
|
as an optimization to generate fewer suggestions to test on each shard and
|
2016-08-26 13:00:49 -04:00
|
|
|
are not rechecked when combining the suggestions generated on each
|
2016-01-04 14:48:56 -05:00
|
|
|
shard. Thus `missing` will generate suggestions for terms on shards that do
|
2019-02-20 04:36:37 -05:00
|
|
|
not contain them even if other shards do contain them. Those should be
|
2016-01-04 14:48:56 -05:00
|
|
|
filtered out using `confidence`. Three possible values can be specified:
|
|
|
|
** `missing`: Only generate suggestions for terms that are not in the
|
|
|
|
shard. This is the default.
|
2016-11-18 06:05:49 -05:00
|
|
|
** `popular`: Only suggest terms that occur in more docs on the shard than
|
2016-01-04 14:48:56 -05:00
|
|
|
the original term.
|
2013-08-28 19:24:34 -04:00
|
|
|
** `always`: Suggest any matching suggestions based on terms in the
|
|
|
|
suggest text.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`max_edits`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The maximum edit distance candidate suggestions can have
|
|
|
|
in order to be considered as a suggestion. Can only be a value between 1
|
2019-02-20 04:36:37 -05:00
|
|
|
and 2. Any other value results in a bad request error being thrown.
|
2013-08-28 19:24:34 -04:00
|
|
|
Defaults to 2.
|
|
|
|
|
2014-01-02 11:11:20 -05:00
|
|
|
`prefix_length`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The number of minimal prefix characters that must
|
|
|
|
match in order be a candidate suggestions. Defaults to 1. Increasing
|
|
|
|
this number improves spellcheck performance. Usually misspellings don't
|
2014-01-02 11:11:20 -05:00
|
|
|
occur in the beginning of terms. (Old name "prefix_len" is deprecated)
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`min_word_length`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The minimum length a suggest text term must have in
|
2014-01-02 11:11:20 -05:00
|
|
|
order to be included. Defaults to 4. (Old name "min_word_len" is deprecated)
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`max_inspections`::
|
2013-08-28 19:24:34 -04:00
|
|
|
A factor that is used to multiply with the
|
2019-02-20 04:36:37 -05:00
|
|
|
`shards_size` in order to inspect more candidate spelling corrections on
|
2013-08-28 19:24:34 -04:00
|
|
|
the shard level. Can improve accuracy at the cost of performance.
|
|
|
|
Defaults to 5.
|
|
|
|
|
|
|
|
`min_doc_freq`::
|
|
|
|
The minimal threshold in number of documents a
|
|
|
|
suggestion should appear in. This can be specified as an absolute number
|
|
|
|
or as a relative percentage of number of documents. This can improve
|
|
|
|
quality by only suggesting high frequency terms. Defaults to 0f and is
|
2019-02-20 04:36:37 -05:00
|
|
|
not enabled. If a value higher than 1 is specified, then the number
|
2013-08-28 19:24:34 -04:00
|
|
|
cannot be fractional. The shard level document frequencies are used for
|
|
|
|
this option.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`max_term_freq`::
|
2019-02-20 04:36:37 -05:00
|
|
|
The maximum threshold in number of documents in which a
|
2013-08-28 19:24:34 -04:00
|
|
|
suggest text token can exist in order to be included. Can be a relative
|
2019-02-20 04:36:37 -05:00
|
|
|
percentage number (e.g., 0.4) or an absolute number to represent document
|
|
|
|
frequencies. If a value higher than 1 is specified, then fractional can
|
2013-08-28 19:24:34 -04:00
|
|
|
not be specified. Defaults to 0.01f. This can be used to exclude high
|
2019-02-20 04:36:37 -05:00
|
|
|
frequency terms -- which are usually spelled correctly -- from being spellchecked. This also improves the spellcheck
|
2013-08-28 19:24:34 -04:00
|
|
|
performance. The shard level document frequencies are used for this
|
|
|
|
option.
|
|
|
|
|
|
|
|
`pre_filter`::
|
2019-02-20 04:36:37 -05:00
|
|
|
A filter (analyzer) that is applied to each of the
|
2013-08-28 19:24:34 -04:00
|
|
|
tokens passed to this candidate generator. This filter is applied to the
|
|
|
|
original token before candidates are generated.
|
|
|
|
|
2016-01-04 14:48:56 -05:00
|
|
|
`post_filter`::
|
2019-02-20 04:36:37 -05:00
|
|
|
A filter (analyzer) that is applied to each of the
|
2013-08-28 19:24:34 -04:00
|
|
|
generated tokens before they are passed to the actual phrase scorer.
|
|
|
|
|
2019-02-20 04:36:37 -05:00
|
|
|
The following example shows a `phrase` suggest call with two generators:
|
|
|
|
the first one is using a field containing ordinary indexed terms, and the
|
2016-01-04 14:48:56 -05:00
|
|
|
second one uses a field that uses terms indexed with a `reverse` filter
|
|
|
|
(tokens are index in reverse order). This is used to overcome the limitation
|
|
|
|
of the direct generators to require a constant prefix to provide
|
|
|
|
high-performance suggestions. The `pre_filter` and `post_filter` options
|
2013-08-28 19:24:34 -04:00
|
|
|
accept ordinary analyzer names.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2019-06-21 05:15:51 -04:00
|
|
|
POST test/_search
|
2016-07-22 18:51:36 -04:00
|
|
|
{
|
2016-12-14 21:49:53 -05:00
|
|
|
"suggest": {
|
|
|
|
"text" : "obel prize",
|
|
|
|
"simple_phrase" : {
|
|
|
|
"phrase" : {
|
2016-07-22 18:51:36 -04:00
|
|
|
"field" : "title.trigram",
|
2016-12-14 21:49:53 -05:00
|
|
|
"size" : 1,
|
|
|
|
"direct_generator" : [ {
|
|
|
|
"field" : "title.trigram",
|
|
|
|
"suggest_mode" : "always"
|
|
|
|
}, {
|
|
|
|
"field" : "title.reverse",
|
|
|
|
"suggest_mode" : "always",
|
|
|
|
"pre_filter" : "reverse",
|
|
|
|
"post_filter" : "reverse"
|
|
|
|
} ]
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-07-22 18:51:36 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
`pre_filter` and `post_filter` can also be used to inject synonyms after
|
|
|
|
candidates are generated. For instance for the query `captain usq` we
|
2019-02-20 04:36:37 -05:00
|
|
|
might generate a candidate `usa` for the term `usq`, which is a synonym for
|
|
|
|
`america`. This allows us to present `captain america` to the user if this
|
2013-08-28 19:24:34 -04:00
|
|
|
phrase scores high enough.
|