|
24 | 24 | import org.elasticsearch.common.bytes.BytesReference;
|
25 | 25 | import org.elasticsearch.common.io.stream.StreamInput;
|
26 | 26 | import org.elasticsearch.common.io.stream.StreamOutput;
|
| 27 | +import org.elasticsearch.common.logging.DeprecationLogger; |
| 28 | +import org.elasticsearch.common.logging.Loggers; |
27 | 29 | import org.elasticsearch.common.unit.Fuzziness;
|
28 | 30 | import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
29 | 31 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
57 | 59 | * indexing.
|
58 | 60 | */
|
59 | 61 | public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder> {
|
| 62 | + |
| 63 | + private static final DeprecationLogger DEPRECATION_LOGGER = |
| 64 | + new DeprecationLogger(Loggers.getLogger(CompletionSuggestionBuilder.class)); |
| 65 | + |
60 | 66 | private static final XContentType CONTEXT_BYTES_XCONTENT_TYPE = XContentType.JSON;
|
61 | 67 | static final String SUGGESTION_NAME = "completion";
|
62 | 68 | static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
|
@@ -298,16 +304,19 @@ public SuggestionContext build(QueryShardContext context) throws IOException {
|
298 | 304 | if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) {
|
299 | 305 | throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field");
|
300 | 306 | }
|
301 |
| - if (mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType) { |
302 |
| - CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; |
303 |
| - suggestionContext.setFieldType(type); |
304 |
| - if (type.hasContextMappings() && contextBytes != null) { |
| 307 | + CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; |
| 308 | + suggestionContext.setFieldType(type); |
| 309 | + if (type.hasContextMappings()) { |
| 310 | + if (contextBytes == null) { |
| 311 | + DEPRECATION_LOGGER.deprecated("The ability to query with no context on a context enabled completion field is deprecated " + |
| 312 | + "and will be removed in the next major release."); |
| 313 | + } else { |
305 | 314 | Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(contextBytes,
|
306 |
| - context.getXContentRegistry(), type.getContextMappings()); |
| 315 | + context.getXContentRegistry(), type.getContextMappings()); |
307 | 316 | suggestionContext.setQueryContexts(queryContexts);
|
308 |
| - } else if (contextBytes != null) { |
309 |
| - throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); |
310 | 317 | }
|
| 318 | + } else if (contextBytes != null) { |
| 319 | + throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); |
311 | 320 | }
|
312 | 321 | assert suggestionContext.getFieldType() != null : "no completion field type set";
|
313 | 322 | return suggestionContext;
|
|
0 commit comments