Skip to content

Commit a577a1a

Browse files
committed
Clarify context suggestions filtering and boosting (#33601)
This change clarifies the documentation of the context completion suggester regarding filtering and boosting with contexts. Unlike the suggester v1, filtering on multiple contexts works as a disjunction, a suggestion matches if it contains at least one of the provided context values and boosting selects the maximum score among the matching contexts. This commit also adapts an old test that was written for the v1 suggester and commented out for version 2 because the behavior changed.
1 parent 8915d3c commit a577a1a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

docs/reference/search/suggesters/context-suggest.asciidoc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Every context mapping has a unique name and a type. There are two types: `catego
1313
and `geo`. Context mappings are configured under the `contexts` parameter in
1414
the field mapping.
1515

16+
NOTE: It is mandatory to provide a context when indexing and querying
17+
a context enabled completion field.
18+
1619
The following defines types, each with two context mappings for a completion
1720
field:
1821

@@ -84,10 +87,6 @@ PUT place_path_category
8487
NOTE: Adding context mappings increases the index size for completion field. The completion index
8588
is entirely heap resident, you can monitor the completion field index size using <<indices-stats>>.
8689

87-
NOTE: deprecated[7.0.0, Indexing a suggestion without context on a context enabled completion field is deprecated
88-
and will be removed in the next major release. If you want to index a suggestion that matches all contexts you should
89-
add a special context for it.]
90-
9190
[[suggester-context-category]]
9291
[float]
9392
==== Category Context
@@ -160,9 +159,9 @@ POST place/_search?pretty
160159
// CONSOLE
161160
// TEST[continued]
162161

163-
Note: deprecated[7.0.0, When no categories are provided at query-time, all indexed documents are considered.
164-
Querying with no categories on a category enabled completion field is deprecated and will be removed in the next major release
165-
as it degrades search performance considerably.]
162+
NOTE: If multiple categories or category contexts are set on the query
163+
they are merged as a disjunction. This means that suggestions match
164+
if they contain at least one of the provided context values.
166165

167166
Suggestions with certain categories can be boosted higher than others.
168167
The following filters suggestions by categories and additionally boosts
@@ -218,6 +217,9 @@ multiple category context clauses. The following parameters are supported for a
218217
so on, by specifying a category prefix of 'type'.
219218
Defaults to `false`
220219

220+
NOTE: If a suggestion entry matches multiple contexts the final score is computed as the
221+
maximum score produced by any matching contexts.
222+
221223
[[suggester-context-geo]]
222224
[float]
223225
==== Geo location Context
@@ -307,6 +309,10 @@ POST place/_search
307309
NOTE: When a location with a lower precision at query time is specified, all suggestions
308310
that fall within the area will be considered.
309311

312+
NOTE: If multiple categories or category contexts are set on the query
313+
they are merged as a disjunction. This means that suggestions match
314+
if they contain at least one of the provided context values.
315+
310316
Suggestions that are within an area represented by a geohash can also be boosted higher
311317
than others, as shown by the following:
312318

@@ -349,6 +355,9 @@ POST place/_search?pretty
349355
that fall under the geohash representation of '(43.6624803, -79.3863353)'
350356
with a default precision of '6' by a factor of `2`
351357

358+
NOTE: If a suggestion entry matches multiple contexts the final score is computed as the
359+
maximum score produced by any matching contexts.
360+
352361
In addition to accepting context values, a context query can be composed of
353362
multiple context clauses. The following parameters are supported for a
354363
`category` context clause:

server/src/test/java/org/elasticsearch/search/suggest/ContextCompletionSuggestSearchIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ public void testMultiContextFiltering() throws Exception {
304304
assertSuggestions("foo", multiContextFilterSuggest, "suggestion6", "suggestion2");
305305
}
306306

307-
@AwaitsFix(bugUrl = "multiple context boosting is broken, as a suggestion, contexts pair is treated as (num(context) entries)")
308307
public void testMultiContextBoosting() throws Exception {
309308
LinkedHashMap<String, ContextMapping> map = new LinkedHashMap<>();
310309
map.put("cat", ContextBuilder.category("cat").field("cat").build());
@@ -357,7 +356,8 @@ public void testMultiContextBoosting() throws Exception {
357356
CategoryQueryContext.builder().setCategory("cat1").build())
358357
);
359358
multiContextBoostSuggest.contexts(contextMap);
360-
assertSuggestions("foo", multiContextBoostSuggest, "suggestion9", "suggestion6", "suggestion5", "suggestion2", "suggestion1");
359+
// the score of each suggestion is the maximum score among the matching contexts
360+
assertSuggestions("foo", multiContextBoostSuggest, "suggestion9", "suggestion8", "suggestion5", "suggestion6", "suggestion4");
361361
}
362362

363363
public void testMissingContextValue() throws Exception {

0 commit comments

Comments
 (0)