static TermSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); TermSuggestionBuilder tmpSuggestion = new TermSuggestionBuilder("_na_"); ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String currentFieldName = null; String fieldname = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.ANALYZER_FIELD)) { tmpSuggestion.analyzer(parser.text()); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.FIELDNAME_FIELD)) { fieldname = parser.text(); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SIZE_FIELD)) { tmpSuggestion.size(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SHARDSIZE_FIELD)) { tmpSuggestion.shardSize(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, SUGGESTMODE_FIELD)) { tmpSuggestion.suggestMode(SuggestMode.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, ACCURACY_FIELD)) { tmpSuggestion.accuracy(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, SORT_FIELD)) { tmpSuggestion.sort(SortBy.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, STRING_DISTANCE_FIELD)) { tmpSuggestion.stringDistance(StringDistanceImpl.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, MAX_EDITS_FIELD)) { tmpSuggestion.maxEdits(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MAX_INSPECTIONS_FIELD)) { tmpSuggestion.maxInspections(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MAX_TERM_FREQ_FIELD)) { tmpSuggestion.maxTermFreq(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, PREFIX_LENGTH_FIELD)) { tmpSuggestion.prefixLength(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MIN_WORD_LENGTH_FIELD)) { tmpSuggestion.minWordLength(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MIN_DOC_FREQ_FIELD)) { tmpSuggestion.minDocFreq(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, EXACT_MATCH_FIELD)) { tmpSuggestion.exactMatch(parser.booleanValue()); } else { throw new ParsingException( parser.getTokenLocation(), "suggester[term] doesn't support field [" + currentFieldName + "]"); } } else { throw new ParsingException( parser.getTokenLocation(), "suggester[term] parsing failed on [" + currentFieldName + "]"); } } // now we should have field name, check and copy fields over to the suggestion builder we return if (fieldname == null) { throw new ElasticsearchParseException( "the required field option [" + FIELDNAME_FIELD.getPreferredName() + "] is missing"); } return new TermSuggestionBuilder(fieldname, tmpSuggestion); }