diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java index 141e41e826b..00592e6c984 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java @@ -63,10 +63,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder TLP_PARSER = + private static ObjectParser TLP_PARSER = new ObjectParser<>(SUGGESTION_NAME, null); static { - TLP_PARSER.declareStringArray(CompletionSuggestionBuilder::payload, PAYLOAD_FIELD); + TLP_PARSER.declareStringArray(CompletionSuggestionBuilder.InnerBuilder::payload, PAYLOAD_FIELD); TLP_PARSER.declareField((parser, completionSuggestionContext, context) -> { if (parser.currentToken() == XContentParser.Token.VALUE_BOOLEAN) { if (parser.booleanValue()) { @@ -80,10 +80,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder completionSuggestionContext.regexOptions = RegexOptions.parse(parser), RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT); - TLP_PARSER.declareString(CompletionSuggestionBuilder::field, SuggestUtils.Fields.FIELD); - TLP_PARSER.declareString(CompletionSuggestionBuilder::analyzer, SuggestUtils.Fields.ANALYZER); - TLP_PARSER.declareInt(CompletionSuggestionBuilder::size, SuggestUtils.Fields.SIZE); - TLP_PARSER.declareInt(CompletionSuggestionBuilder::shardSize, SuggestUtils.Fields.SHARD_SIZE); + TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, SuggestUtils.Fields.FIELD); + TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, SuggestUtils.Fields.ANALYZER); + TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::size, SuggestUtils.Fields.SIZE); + TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::shardSize, SuggestUtils.Fields.SHARD_SIZE); TLP_PARSER.declareField((p, v, c) -> { // Copy the current structure. We will parse, once the mapping is provided XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); @@ -93,10 +93,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder payloadFields = Collections.emptyList(); + protected FuzzyOptions fuzzyOptions; + protected RegexOptions regexOptions; + protected BytesReference contextBytes = null; + protected List payloadFields = Collections.emptyList(); public CompletionSuggestionBuilder(String fieldname) { super(fieldname); @@ -167,6 +167,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder fields) { + Objects.requireNonNull(fields, "payload must not be null"); this.payloadFields = fields; return this; } @@ -178,6 +179,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder> queryContexts) { + Objects.requireNonNull(queryContexts, "contexts must not be null"); try { XContentBuilder contentBuilder = XContentFactory.jsonBuilder(); contentBuilder.startObject(); @@ -196,10 +198,17 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder(mapperService, builder); + return new Tuple<>(mapperService, builderAndInfo.builder); } @Override