Deprecates indexing and querying a context completion field without context (#30712)
This change deprecates completion queries and documents without context that target a context enabled completion field. Querying without context degrades the search performance considerably (even when the number of indexed contexts is low). This commit targets master but the deprecation will take place in 6.x and the functionality will be removed in 7 in a follow up. Closes #29222
This commit is contained in:
parent
63f3a61134
commit
0f5e570184
|
@ -84,6 +84,10 @@ PUT place_path_category
|
||||||
NOTE: Adding context mappings increases the index size for completion field. The completion index
|
NOTE: Adding context mappings increases the index size for completion field. The completion index
|
||||||
is entirely heap resident, you can monitor the completion field index size using <<indices-stats>>.
|
is entirely heap resident, you can monitor the completion field index size using <<indices-stats>>.
|
||||||
|
|
||||||
|
NOTE: deprecated[7.0.0, Indexing a suggestion without context on a context enabled completion field is deprecated
|
||||||
|
and will be removed in the next major release. If you want to index a suggestion that matches all contexts you should
|
||||||
|
add a special context for it.]
|
||||||
|
|
||||||
[[suggester-context-category]]
|
[[suggester-context-category]]
|
||||||
[float]
|
[float]
|
||||||
==== Category Context
|
==== Category Context
|
||||||
|
@ -156,9 +160,9 @@ POST place/_search?pretty
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
// TEST[continued]
|
// TEST[continued]
|
||||||
|
|
||||||
NOTE: When no categories are provided at query-time, all indexed documents are considered.
|
Note: deprecated[7.0.0, When no categories are provided at query-time, all indexed documents are considered.
|
||||||
Querying with no categories on a category enabled completion field should be avoided, as it
|
Querying with no categories on a category enabled completion field is deprecated and will be removed in the next major release
|
||||||
will degrade search performance.
|
as it degrades search performance considerably.]
|
||||||
|
|
||||||
Suggestions with certain categories can be boosted higher than others.
|
Suggestions with certain categories can be boosted higher than others.
|
||||||
The following filters suggestions by categories and additionally boosts
|
The following filters suggestions by categories and additionally boosts
|
||||||
|
|
|
@ -336,16 +336,80 @@ setup:
|
||||||
- length: { suggest.result.0.options: 1 }
|
- length: { suggest.result.0.options: 1 }
|
||||||
- match: { suggest.result.0.options.0.text: "foo" }
|
- match: { suggest.result.0.options.0.text: "foo" }
|
||||||
|
|
||||||
|
---
|
||||||
|
"Indexing and Querying without contexts is deprecated":
|
||||||
|
- skip:
|
||||||
|
version: " - 6.99.99"
|
||||||
|
reason: this feature was deprecated in 7.0
|
||||||
|
features: "warnings"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
type: test
|
||||||
|
id: 1
|
||||||
|
body:
|
||||||
|
suggest_context:
|
||||||
|
input: "foo"
|
||||||
|
contexts:
|
||||||
|
color: "red"
|
||||||
|
suggest_multi_contexts:
|
||||||
|
input: "bar"
|
||||||
|
contexts:
|
||||||
|
color: "blue"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to index a suggestion with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
type: test
|
||||||
|
id: 2
|
||||||
|
body:
|
||||||
|
suggest_context:
|
||||||
|
input: "foo"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
indices.refresh: {}
|
||||||
|
|
||||||
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to query with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
search:
|
search:
|
||||||
body:
|
body:
|
||||||
suggest:
|
suggest:
|
||||||
result:
|
result:
|
||||||
text: "foo"
|
text: "foo"
|
||||||
completion:
|
completion:
|
||||||
skip_duplicates: true
|
|
||||||
field: suggest_context
|
field: suggest_context
|
||||||
|
|
||||||
- length: { suggest.result: 1 }
|
- length: { suggest.result: 1 }
|
||||||
- length: { suggest.result.0.options: 1 }
|
|
||||||
- match: { suggest.result.0.options.0.text: "foo" }
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to query with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
|
search:
|
||||||
|
body:
|
||||||
|
suggest:
|
||||||
|
result:
|
||||||
|
text: "foo"
|
||||||
|
completion:
|
||||||
|
field: suggest_context
|
||||||
|
contexts: {}
|
||||||
|
|
||||||
|
- length: { suggest.result: 1 }
|
||||||
|
|
||||||
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to query with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
|
search:
|
||||||
|
body:
|
||||||
|
suggest:
|
||||||
|
result:
|
||||||
|
text: "foo"
|
||||||
|
completion:
|
||||||
|
field: suggest_multi_contexts
|
||||||
|
contexts:
|
||||||
|
location: []
|
||||||
|
|
||||||
|
- length: { suggest.result: 1 }
|
||||||
|
|
|
@ -19,6 +19,8 @@ setup:
|
||||||
"type" : "category"
|
"type" : "category"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to index a suggestion with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
bulk:
|
bulk:
|
||||||
refresh: true
|
refresh: true
|
||||||
index: test
|
index: test
|
||||||
|
@ -31,8 +33,14 @@ setup:
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test typed keys parameter for suggesters":
|
"Test typed keys parameter for suggesters":
|
||||||
|
- skip:
|
||||||
|
version: " - 6.99.99"
|
||||||
|
reason: queying a context suggester with no context was deprecated in 7.0
|
||||||
|
features: "warnings"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
warnings:
|
||||||
|
- "The ability to query with no context on a context enabled completion field is deprecated and will be removed in the next major release."
|
||||||
search:
|
search:
|
||||||
typed_keys: true
|
typed_keys: true
|
||||||
body:
|
body:
|
||||||
|
|
|
@ -83,7 +83,6 @@ import static org.elasticsearch.index.mapper.TypeParsers.parseMultiField;
|
||||||
* for query-time filtering and boosting (see {@link ContextMappings}
|
* for query-time filtering and boosting (see {@link ContextMappings}
|
||||||
*/
|
*/
|
||||||
public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapperParser {
|
public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapperParser {
|
||||||
|
|
||||||
public static final String CONTENT_TYPE = "completion";
|
public static final String CONTENT_TYPE = "completion";
|
||||||
|
|
||||||
public static class Defaults {
|
public static class Defaults {
|
||||||
|
|
|
@ -57,6 +57,7 @@ import java.util.Objects;
|
||||||
* indexing.
|
* indexing.
|
||||||
*/
|
*/
|
||||||
public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder> {
|
public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder> {
|
||||||
|
|
||||||
private static final XContentType CONTEXT_BYTES_XCONTENT_TYPE = XContentType.JSON;
|
private static final XContentType CONTEXT_BYTES_XCONTENT_TYPE = XContentType.JSON;
|
||||||
static final String SUGGESTION_NAME = "completion";
|
static final String SUGGESTION_NAME = "completion";
|
||||||
static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
|
static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
|
||||||
|
|
|
@ -25,6 +25,8 @@ import org.apache.lucene.search.suggest.document.ContextSuggestField;
|
||||||
import org.apache.lucene.util.CharsRefBuilder;
|
import org.apache.lucene.util.CharsRefBuilder;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||||
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.mapper.CompletionFieldMapper;
|
import org.elasticsearch.index.mapper.CompletionFieldMapper;
|
||||||
|
@ -51,6 +53,10 @@ import static org.elasticsearch.search.suggest.completion.context.ContextMapping
|
||||||
* for a {@link CompletionFieldMapper}
|
* for a {@link CompletionFieldMapper}
|
||||||
*/
|
*/
|
||||||
public class ContextMappings implements ToXContent {
|
public class ContextMappings implements ToXContent {
|
||||||
|
|
||||||
|
private static final DeprecationLogger DEPRECATION_LOGGER =
|
||||||
|
new DeprecationLogger(Loggers.getLogger(ContextMappings.class));
|
||||||
|
|
||||||
private final List<ContextMapping> contextMappings;
|
private final List<ContextMapping> contextMappings;
|
||||||
private final Map<String, ContextMapping> contextNameMap;
|
private final Map<String, ContextMapping> contextNameMap;
|
||||||
|
|
||||||
|
@ -143,6 +149,10 @@ public class ContextMappings implements ToXContent {
|
||||||
scratch.setLength(1);
|
scratch.setLength(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typedContexts.isEmpty()) {
|
||||||
|
DEPRECATION_LOGGER.deprecated("The ability to index a suggestion with no context on a context enabled completion field" +
|
||||||
|
" is deprecated and will be removed in the next major release.");
|
||||||
|
}
|
||||||
return typedContexts;
|
return typedContexts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +166,7 @@ public class ContextMappings implements ToXContent {
|
||||||
*/
|
*/
|
||||||
public ContextQuery toContextQuery(CompletionQuery query, Map<String, List<ContextMapping.InternalQueryContext>> queryContexts) {
|
public ContextQuery toContextQuery(CompletionQuery query, Map<String, List<ContextMapping.InternalQueryContext>> queryContexts) {
|
||||||
ContextQuery typedContextQuery = new ContextQuery(query);
|
ContextQuery typedContextQuery = new ContextQuery(query);
|
||||||
|
boolean hasContext = false;
|
||||||
if (queryContexts.isEmpty() == false) {
|
if (queryContexts.isEmpty() == false) {
|
||||||
CharsRefBuilder scratch = new CharsRefBuilder();
|
CharsRefBuilder scratch = new CharsRefBuilder();
|
||||||
scratch.grow(1);
|
scratch.grow(1);
|
||||||
|
@ -169,10 +180,15 @@ public class ContextMappings implements ToXContent {
|
||||||
scratch.append(context.context);
|
scratch.append(context.context);
|
||||||
typedContextQuery.addContext(scratch.toCharsRef(), context.boost, !context.isPrefix);
|
typedContextQuery.addContext(scratch.toCharsRef(), context.boost, !context.isPrefix);
|
||||||
scratch.setLength(1);
|
scratch.setLength(1);
|
||||||
|
hasContext = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hasContext == false) {
|
||||||
|
DEPRECATION_LOGGER.deprecated("The ability to query with no context on a context enabled completion field is deprecated " +
|
||||||
|
"and will be removed in the next major release.");
|
||||||
|
}
|
||||||
return typedContextQuery;
|
return typedContextQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue