throw new IllegalArgumentException("contexts field is not supported for field: [" + fieldType().name() + "]"); ContextMappings contextMappings = fieldType().getContextMappings(); XContentParser.Token currentToken = parser.currentToken(); if (currentToken == XContentParser.Token.START_OBJECT) {
fieldType().getContextMappings().addField(context.doc(), fieldType().name(), input, metaData.weight, metaData.contexts); } else {
/** * Verifies that all field paths specified in contexts point to the fields with correct mappings */ public static void validateContextPaths(Version indexVersionCreated, List<FieldMapper> fieldMappers, Function<String, MappedFieldType> fieldResolver) { for (FieldMapper fieldMapper : fieldMappers) { if (CompletionFieldMapper.CONTENT_TYPE.equals(fieldMapper.typeName())) { CompletionFieldMapper.CompletionFieldType fieldType = ((CompletionFieldMapper) fieldMapper).fieldType(); if (fieldType.hasContextMappings()) { for (ContextMapping context : fieldType.getContextMappings()) { context.validateReferences(indexVersionCreated, fieldResolver); } } } } }
fieldType().getContextMappings().addField(context.doc(), fieldType().name(), input, metaData.weight, metaData.contexts); } else {
contextBytes)) { if (type.hasContextMappings() && contextParser != null) { ContextMappings contextMappings = type.getContextMappings(); contextParser.nextToken(); Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = new HashMap<>(contextMappings.size());
fieldType().getContextMappings().addField(context.doc(), fieldType().name(), input, metaData.weight, metaData.contexts); } else {
contexts = fieldType.getContextMappings().getNamedContexts(suggestDoc.getContexts());
List<CharSequence> rawContexts = collector.getContexts(suggestDoc.doc); if (rawContexts.size() > 0) { contexts = fieldType.getContextMappings().getNamedContexts(rawContexts);
@Override public SuggestionContext build(QueryShardContext context) throws IOException { CompletionSuggestionContext suggestionContext = new CompletionSuggestionContext(context); // copy over common settings to each suggestion builder final MapperService mapperService = context.getMapperService(); populateCommonFields(mapperService, suggestionContext); suggestionContext.setSkipDuplicates(skipDuplicates); suggestionContext.setFuzzyOptions(fuzzyOptions); suggestionContext.setRegexOptions(regexOptions); if (shardSize != null) { suggestionContext.setShardSize(shardSize); } MappedFieldType mappedFieldType = mapperService.fullName(suggestionContext.getField()); if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) { throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field"); } if (mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType) { CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; suggestionContext.setFieldType(type); if (type.hasContextMappings() && contextBytes != null) { Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(contextBytes, context.getXContentRegistry(), type.getContextMappings()); suggestionContext.setQueryContexts(queryContexts); } else if (contextBytes != null) { throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); } } assert suggestionContext.getFieldType() != null : "no completion field type set"; return suggestionContext; }
@Override public SuggestionContext build(QueryShardContext context) throws IOException { CompletionSuggestionContext suggestionContext = new CompletionSuggestionContext(context); // copy over common settings to each suggestion builder final MapperService mapperService = context.getMapperService(); populateCommonFields(mapperService, suggestionContext); suggestionContext.setSkipDuplicates(skipDuplicates); suggestionContext.setFuzzyOptions(fuzzyOptions); suggestionContext.setRegexOptions(regexOptions); if (shardSize != null) { suggestionContext.setShardSize(shardSize); } MappedFieldType mappedFieldType = mapperService.fullName(suggestionContext.getField()); if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) { throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field"); } if (mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType) { CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; suggestionContext.setFieldType(type); if (type.hasContextMappings() && contextBytes != null) { Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(contextBytes, context.getXContentRegistry(), type.getContextMappings()); suggestionContext.setQueryContexts(queryContexts); } else if (contextBytes != null) { throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); } } assert suggestionContext.getFieldType() != null : "no completion field type set"; return suggestionContext; }
CompletionQuery toQuery() { CompletionFieldMapper.CompletionFieldType fieldType = getFieldType(); final CompletionQuery query; if (getPrefix() != null) { query = createCompletionQuery(getPrefix(), fieldType); } else if (getRegex() != null) { if (fuzzyOptions != null) { throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex"); } if (regexOptions == null) { regexOptions = RegexOptions.builder().build(); } query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(), regexOptions.getMaxDeterminizedStates()); } else if (getText() != null) { query = createCompletionQuery(getText(), fieldType); } else { throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined"); } if (fieldType.hasContextMappings()) { ContextMappings contextMappings = fieldType.getContextMappings(); return contextMappings.toContextQuery(query, queryContexts); } return query; }
CompletionQuery toQuery() { CompletionFieldMapper.CompletionFieldType fieldType = getFieldType(); final CompletionQuery query; if (getPrefix() != null) { query = createCompletionQuery(getPrefix(), fieldType); } else if (getRegex() != null) { if (fuzzyOptions != null) { throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex"); } if (regexOptions == null) { regexOptions = RegexOptions.builder().build(); } query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(), regexOptions.getMaxDeterminizedStates()); } else if (getText() != null) { query = createCompletionQuery(getText(), fieldType); } else { throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined"); } if (fieldType.hasContextMappings()) { ContextMappings contextMappings = fieldType.getContextMappings(); return contextMappings.toContextQuery(query, queryContexts); } return query; }
CompletionQuery toQuery() { CompletionFieldMapper.CompletionFieldType fieldType = getFieldType(); final CompletionQuery query; if (getPrefix() != null) { query = createCompletionQuery(getPrefix(), fieldType); } else if (getRegex() != null) { if (fuzzyOptions != null) { throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex"); } if (regexOptions == null) { regexOptions = RegexOptions.builder().build(); } query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(), regexOptions.getMaxDeterminizedStates()); } else if (getText() != null) { query = createCompletionQuery(getText(), fieldType); } else { throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined"); } if (fieldType.hasContextMappings()) { ContextMappings contextMappings = fieldType.getContextMappings(); return contextMappings.toContextQuery(query, queryContexts); } return query; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE.getPreferredName(), CONTENT_TYPE); builder.field(Fields.ANALYZER.getPreferredName(), fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().preserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().preservePositionIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); if (fieldType().hasContextMappings()) { builder.startArray(Fields.CONTEXTS.getPreferredName()); fieldType().getContextMappings().toXContent(builder, params); builder.endArray(); } multiFields.toXContent(builder, params); return builder.endObject(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE.getPreferredName(), CONTENT_TYPE); builder.field(Fields.ANALYZER.getPreferredName(), fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().preserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().preservePositionIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); if (fieldType().hasContextMappings()) { builder.startArray(Fields.CONTEXTS.getPreferredName()); fieldType().getContextMappings().toXContent(builder, params); builder.endArray(); } multiFields.toXContent(builder, params); return builder.endObject(); }
/** * Verifies that all field paths specified in contexts point to the fields with correct mappings */ public static void validateContextPaths(Version indexVersionCreated, List<FieldMapper> fieldMappers, Function<String, MappedFieldType> fieldResolver) { for (FieldMapper fieldMapper : fieldMappers) { if (CompletionFieldMapper.CONTENT_TYPE.equals(fieldMapper.typeName())) { CompletionFieldMapper.CompletionFieldType fieldType = ((CompletionFieldMapper) fieldMapper).fieldType(); if (fieldType.hasContextMappings()) { for (ContextMapping context : fieldType.getContextMappings()) { context.validateReferences(indexVersionCreated, fieldResolver); } } } } }
List<CharSequence> rawContexts = collector.getContexts(suggestDoc.doc); if (rawContexts.size() > 0) { contexts = fieldType.getContextMappings().getNamedContexts(rawContexts);
@Override public SuggestionContext build(QueryShardContext context) throws IOException { CompletionSuggestionContext suggestionContext = new CompletionSuggestionContext(context); // copy over common settings to each suggestion builder final MapperService mapperService = context.getMapperService(); populateCommonFields(mapperService, suggestionContext); suggestionContext.setSkipDuplicates(skipDuplicates); suggestionContext.setFuzzyOptions(fuzzyOptions); suggestionContext.setRegexOptions(regexOptions); if (shardSize != null) { suggestionContext.setShardSize(shardSize); } MappedFieldType mappedFieldType = mapperService.fullName(suggestionContext.getField()); if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) { throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field"); } if (mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType) { CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; suggestionContext.setFieldType(type); if (type.hasContextMappings() && contextBytes != null) { Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(contextBytes, context.getXContentRegistry(), type.getContextMappings()); suggestionContext.setQueryContexts(queryContexts); } else if (contextBytes != null) { throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); } } assert suggestionContext.getFieldType() != null : "no completion field type set"; return suggestionContext; }
CompletionQuery toQuery() { CompletionFieldMapper.CompletionFieldType fieldType = getFieldType(); final CompletionQuery query; if (getPrefix() != null) { query = createCompletionQuery(getPrefix(), fieldType); } else if (getRegex() != null) { if (fuzzyOptions != null) { throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex"); } if (regexOptions == null) { regexOptions = RegexOptions.builder().build(); } query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(), regexOptions.getMaxDeterminizedStates()); } else if (getText() != null) { query = createCompletionQuery(getText(), fieldType); } else { throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined"); } if (fieldType.hasContextMappings()) { ContextMappings contextMappings = fieldType.getContextMappings(); return contextMappings.toContextQuery(query, queryContexts); } return query; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE.getPreferredName(), CONTENT_TYPE); builder.field(Fields.ANALYZER.getPreferredName(), fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().preserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().preservePositionIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); if (fieldType().hasContextMappings()) { builder.startArray(Fields.CONTEXTS.getPreferredName()); fieldType().getContextMappings().toXContent(builder, params); builder.endArray(); } multiFields.toXContent(builder, params); return builder.endObject(); }