public static void checkNoRemainingFields(String fieldName, Map<?, ?> fieldNodeMap, Version indexVersionCreated) { checkNoRemainingFields(fieldNodeMap, indexVersionCreated, "Mapping definition for [" + fieldName + "] has unsupported parameters: "); }
public DocumentMapper parse(@Nullable String type, CompressedXContent source, String defaultSource) throws MapperParsingException { Map<String, Object> mapping = null; if (source != null) { Map<String, Object> root = XContentHelper.convertToMap(source.compressedReference(), true, XContentType.JSON).v2(); Tuple<String, Map<String, Object>> t = extractMapping(type, root); type = t.v1(); mapping = t.v2(); } if (mapping == null) { mapping = new HashMap<>(); } return parse(type, mapping, defaultSource); }
public MapperService(IndexSettings indexSettings, IndexAnalyzers indexAnalyzers, NamedXContentRegistry xContentRegistry, SimilarityService similarityService, MapperRegistry mapperRegistry, Supplier<QueryShardContext> queryShardContextSupplier) { super(indexSettings); this.indexAnalyzers = indexAnalyzers; this.fieldTypes = new FieldTypeLookup(); this.documentParser = new DocumentMapperParser(indexSettings, this, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry, queryShardContextSupplier); this.indexAnalyzer = new MapperAnalyzerWrapper(indexAnalyzers.getDefaultIndexAnalyzer(), p -> p.indexAnalyzer()); this.searchAnalyzer = new MapperAnalyzerWrapper(indexAnalyzers.getDefaultSearchAnalyzer(), p -> p.searchAnalyzer()); this.searchQuoteAnalyzer = new MapperAnalyzerWrapper(indexAnalyzers.getDefaultSearchQuoteAnalyzer(), p -> p.searchQuoteAnalyzer()); this.mapperRegistry = mapperRegistry; if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_rc1)) { if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings())) { DEPRECATION_LOGGER.deprecated("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " is deprecated since indices may not have more than one type anymore."); } this.dynamic = INDEX_MAPPER_DYNAMIC_DEFAULT; } else { this.dynamic = this.indexSettings.getValue(INDEX_MAPPER_DYNAMIC_SETTING); } defaultMappingSource = "{\"_default_\":{}}"; if (logger.isTraceEnabled()) { logger.trace("using dynamic[{}], default mapping source[{}]", dynamic, defaultMappingSource); } else if (logger.isDebugEnabled()) { logger.debug("using dynamic[{}]", dynamic); } }
Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource); if (t.v2() != null) { XContentHelper.mergeDefaults(mapping, t.v2()); Mapper.TypeParser.ParserContext parserContext = parserContext(type); docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext)); fieldNodeMap.remove("type"); checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated()); checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");
Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource); if (t.v2() != null) { XContentHelper.mergeDefaults(mapping, t.v2()); Mapper.TypeParser.ParserContext parserContext = parserContext(type); deprecationLogger.deprecated("Mapping transform is deprecated and will be removed in the next major version"); if (fieldNode instanceof Map) { parseTransform(docBuilder, (Map<String, Object>) fieldNode, parserContext.indexVersionCreated()); } else if (fieldNode instanceof List) { for (Object transformItem: (List)fieldNode) { throw new MapperParsingException("Elements of transform list must be objects but one was: " + fieldNode); parseTransform(docBuilder, (Map<String, Object>) transformItem, parserContext.indexVersionCreated()); docBuilder.put((MetadataFieldMapper.Builder)typeParser.parse(fieldName, fieldNodeMap, parserContext)); fieldNodeMap.remove("type"); checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated()); checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");
public DocumentMapper parse(String mappingType, CompressedXContent mappingSource, boolean applyDefault) throws MapperParsingException { return documentParser.parse(mappingType, mappingSource, applyDefault ? defaultMappingSource : null); }
/** * Given a type (eg. long, string, ...), return an anonymous field mapper that can be used for search operations. */ public MappedFieldType unmappedFieldType(String type) { if (type.equals("string")) { deprecationLogger.deprecated("[unmapped_type:string] should be replaced with [unmapped_type:keyword]"); type = "keyword"; } MappedFieldType fieldType = unmappedFieldTypes.get(type); if (fieldType == null) { final Mapper.TypeParser.ParserContext parserContext = documentMapperParser().parserContext(type); Mapper.TypeParser typeParser = parserContext.typeParser(type); if (typeParser == null) { throw new IllegalArgumentException("No mapper found for type [" + type + "]"); } final Mapper.Builder<?, ?> builder = typeParser.parse("__anonymous_" + type, emptyMap(), parserContext); final BuilderContext builderContext = new BuilderContext(indexSettings.getSettings(), new ContentPath(1)); fieldType = ((FieldMapper)builder.build(builderContext)).fieldType(); // There is no need to synchronize writes here. In the case of concurrent access, we could just // compute some mappers several times, which is not a big deal Map<String, MappedFieldType> newUnmappedFieldTypes = new HashMap<>(unmappedFieldTypes); newUnmappedFieldTypes.put(type, fieldType); unmappedFieldTypes = unmodifiableMap(newUnmappedFieldTypes); } return fieldType; }
public static void checkNoRemainingFields(Map<?, ?> fieldNodeMap, Version indexVersionCreated, String message) { if (!fieldNodeMap.isEmpty()) { throw new MapperParsingException(message + getRemainingFields(fieldNodeMap)); } }
private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException { Map<String, Object> root; try (XContentParser parser = XContentType.JSON.xContent() .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)) { root = parser.mapOrdered(); } catch (Exception e) { throw new MapperParsingException("failed to parse mapping definition", e); } return extractMapping(type, root); }
ParsedDocument parseDocument(SourceToParse source, MetadataFieldMapper[] metadataFieldsMappers) throws MapperParsingException { validateType(source); final Mapping mapping = docMapper.mapping(); final ParseContext.InternalParseContext context; final XContentType xContentType = source.getXContentType(); try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, source.source(), xContentType)) { context = new ParseContext.InternalParseContext(indexSettings, docMapperParser, docMapper, source, parser); validateStart(parser); internalParseDocument(mapping, metadataFieldsMappers, context, parser); validateEnd(parser); } catch (Exception e) { throw wrapInMapperParsingException(source, e); } String remainingPath = context.path().pathAsText(""); if (remainingPath.isEmpty() == false) { throw new IllegalStateException("found leftover path elements: " + remainingPath); } context.postParse(); return parsedDocument(source, context, createDynamicUpdate(mapping, docMapper, context.getDynamicMappers())); }
@Inject public RegisterImageType(Index index, @IndexSettings Settings indexSettings, MapperService mapperService, ThreadPool threadPool) { super(index, indexSettings); mapperService.documentMapperParser().putTypeParser("image", new ImageMapper.TypeParser(threadPool)); } }
Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource); if (t.v2() != null) { XContentHelper.mergeDefaults(mapping, t.v2()); Mapper.TypeParser.ParserContext parserContext = parserContext(type); docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext)); fieldNodeMap.remove("type"); checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated()); checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");
public DocumentMapper parse(@Nullable String type, CompressedXContent source) throws MapperParsingException { return parse(type, source, null); }
public Builder(RootObjectMapper.Builder builder, MapperService mapperService) { final Settings indexSettings = mapperService.getIndexSettings().getSettings(); this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1)); this.rootObjectMapper = builder.build(builderContext); final String type = rootObjectMapper.name(); final DocumentMapper existingMapper = mapperService.documentMapper(type); final Map<String, TypeParser> metadataMapperParsers = mapperService.mapperRegistry.getMetadataMapperParsers(); for (Map.Entry<String, MetadataFieldMapper.TypeParser> entry : metadataMapperParsers.entrySet()) { final String name = entry.getKey(); final MetadataFieldMapper existingMetadataMapper = existingMapper == null ? null : (MetadataFieldMapper) existingMapper.mappers().getMapper(name); final MetadataFieldMapper metadataMapper; if (existingMetadataMapper == null) { final TypeParser parser = entry.getValue(); metadataMapper = parser.getDefault(mapperService.fullName(name), mapperService.documentMapperParser().parserContext(builder.name())); } else { metadataMapper = existingMetadataMapper; } metadataMappers.put(metadataMapper.getClass(), metadataMapper); } }
public static void checkNoRemainingFields(Map<?, ?> fieldNodeMap, Version indexVersionCreated, String message) { if (!fieldNodeMap.isEmpty()) { throw new MapperParsingException(message + getRemainingFields(fieldNodeMap)); } }
private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException { Map<String, Object> root; try (XContentParser parser = XContentType.JSON.xContent() .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)) { root = parser.mapOrdered(); } catch (Exception e) { throw new MapperParsingException("failed to parse mapping definition", e); } return extractMapping(type, root); }
ParsedDocument parseDocument(SourceToParse source) throws MapperParsingException { validateType(source); final Mapping mapping = docMapper.mapping(); final ParseContext.InternalParseContext context; try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(), source.source())) { context = new ParseContext.InternalParseContext(indexSettings.getSettings(), docMapperParser, docMapper, source, parser); validateStart(parser); internalParseDocument(mapping, context, parser); validateEnd(parser); } catch (Exception e) { throw wrapInMapperParsingException(source, e); } String remainingPath = context.path().pathAsText(""); if (remainingPath.isEmpty() == false) { throw new IllegalStateException("found leftover path elements: " + remainingPath); } reverseOrder(context); ParsedDocument doc = parsedDocument(source, context, createDynamicUpdate(mapping, docMapper, context.getDynamicMappers())); return doc; }
@Inject public RegisterOpenNlpType(Index index, @IndexSettings Settings indexSettings, MapperService mapperService, AnalysisService analysisService, OpenNlpService openNlpService) { super(index, indexSettings); mapperService.documentMapperParser().putTypeParser("opennlp", new OpenNlpMapper.TypeParser(analysisService, openNlpService)); } }
DocumentMapperParser.checkNoRemainingFields(fieldName, propNode, parserContext.indexVersionCreated()); iterator.remove(); } else if (isEmptyList) { DocumentMapperParser.checkNoRemainingFields(propsNode, parserContext.indexVersionCreated(), "DocType mapping definition has unsupported parameters: ");
Tuple<String, Map<String, Object>> t = extractMapping(MapperService.DEFAULT_MAPPING, defaultSource); if (t.v2() != null) { XContentHelper.mergeDefaults(mapping, t.v2()); Mapper.TypeParser.ParserContext parserContext = parserContext(type); docBuilder.put(typeParser.parse(fieldName, fieldNodeMap, parserContext)); fieldNodeMap.remove("type"); checkNoRemainingFields(fieldName, fieldNodeMap, parserContext.indexVersionCreated()); checkNoRemainingFields(mapping, parserContext.indexVersionCreated(), "Root mapping definition has unsupported parameters: ");