org.elasticsearch.index.mapper.Mapper Java Examples
The following examples show how to use
org.elasticsearch.index.mapper.Mapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public ObjectMapper includeInAllIfNotSet(Boolean includeInAll) { if (includeInAll == null || this.includeInAll != null) { return this; } ObjectMapper clone = clone(); clone.includeInAll = includeInAll; // when called from outside, apply this on all the inner mappers for (Mapper mapper : clone.mappers.values()) { if (mapper instanceof AllFieldMapper.IncludeInAll) { clone.putMapper(((AllFieldMapper.IncludeInAll) mapper).includeInAllIfNotSet(includeInAll)); } } return clone; }
Example #2
Source File: BundlePlugin.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
@Override public Map<String, Mapper.TypeParser> getMappers() { Map<String, Mapper.TypeParser> extra = new LinkedHashMap<>(); if (settings.getAsBoolean("plugins.xbib.standardnumber.enabled", true)) { extra.put(StandardnumberMapper.MAPPER_TYPE, standardNumberTypeParser); } if (settings.getAsBoolean("plugins.xbib.reference.enabled", true)) { extra.put(ReferenceMapper.CONTENT_TYPE, referenceMapperTypeParser); } if (settings.getAsBoolean("plugins.xbib.langdetect.enabled", true)) { extra.put(LangdetectMapper.CONTENT_TYPE, new LangdetectMapper.TypeParser()); } if (settings.getAsBoolean("plugins.xbib.icu.enabled", true)) { extra.put(IcuCollationKeyFieldMapper.CONTENT_TYPE, new IcuCollationKeyFieldMapper.TypeParser()); } return extra; }
Example #3
Source File: SourceFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { SourceFieldMapper sourceMergeWith = (SourceFieldMapper) mergeWith; List<String> conflicts = new ArrayList<>(); if (this.enabled != sourceMergeWith.enabled) { conflicts.add("Cannot update enabled setting for [_source]"); } if (Arrays.equals(includes(), sourceMergeWith.includes()) == false) { conflicts.add("Cannot update includes setting for [_source]"); } if (Arrays.equals(excludes(), sourceMergeWith.excludes()) == false) { conflicts.add("Cannot update excludes setting for [_source]"); } if (conflicts.isEmpty() == false) { throw new IllegalArgumentException("Can't merge because of conflicts: " + conflicts); } if (sourceMergeWith.compress != null) { this.compress = sourceMergeWith.compress; } if (sourceMergeWith.compressThreshold != -1) { this.compressThreshold = sourceMergeWith.compressThreshold; } }
Example #4
Source File: MinHashFieldMapper.java From elasticsearch-minhash with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(final String name, final Map<String, Object> node, final ParserContext parserContext) throws MapperParsingException { final MinHashFieldMapper.Builder builder = new MinHashFieldMapper.Builder( name); parseField(builder, name, node, parserContext); for (final Iterator<Map.Entry<String, Object>> iterator = node.entrySet() .iterator(); iterator.hasNext();) { final Map.Entry<String, Object> entry = iterator.next(); final String propName = entry.getKey(); final Object propNode = entry.getValue(); if (propName.equals("minhash_analyzer") && propNode != null) { final NamedAnalyzer analyzer = parserContext .getIndexAnalyzers().get(propNode.toString()); builder.minhashAnalyzer(analyzer); iterator.remove(); } else if (propName.equals("copy_bits_to") && propNode != null) { parseCopyBitsFields(propNode, builder); iterator.remove(); } } return builder; }
Example #5
Source File: TTLFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { TTLFieldMapper ttlMergeWith = (TTLFieldMapper) mergeWith; if (ttlMergeWith.enabledState != Defaults.ENABLED_STATE) {//only do something if actually something was set for the document mapper that we merge with if (this.enabledState == EnabledAttributeMapper.ENABLED && ttlMergeWith.enabledState == EnabledAttributeMapper.DISABLED) { throw new IllegalArgumentException("_ttl cannot be disabled once it was enabled."); } else { this.enabledState = ttlMergeWith.enabledState; } } if (ttlMergeWith.defaultTTL != -1) { // we never build the default when the field is disabled so we should also not set it // (it does not make a difference though as everything that is not build in toXContent will also not be set in the cluster) if (enabledState == EnabledAttributeMapper.ENABLED) { this.defaultTTL = ttlMergeWith.defaultTTL; } } }
Example #6
Source File: IpFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { IpFieldMapper.Builder builder = ipField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(propNode.toString()); iterator.remove(); } } return builder; }
Example #7
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Y build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); context.path().add(name); Map<String, Mapper> mappers = new HashMap<>(); for (Mapper.Builder builder : mappersBuilders) { Mapper mapper = builder.build(context); mappers.put(mapper.simpleName(), mapper); } context.path().pathType(origPathType); context.path().remove(); ObjectMapper objectMapper = createMapper(name, context.path().fullPathAsText(name), enabled, nested, dynamic, pathType, mappers, context.indexSettings()); objectMapper = objectMapper.includeInAllIfNotSet(includeInAll); return (Y) objectMapper; }
Example #8
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
ObjectMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map<String, Mapper> mappers) { super(name); this.fullPath = fullPath; this.enabled = enabled; this.nested = nested; this.dynamic = dynamic; this.pathType = pathType; if (mappers == null) { this.mappers = new CopyOnWriteHashMap<>(); } else { this.mappers = CopyOnWriteHashMap.copyOf(mappers); } this.nestedTypePathAsString = "__" + fullPath; this.nestedTypePathAsBytes = new BytesRef(nestedTypePathAsString); this.nestedTypeFilter = new TermQuery(new Term(TypeFieldMapper.NAME, nestedTypePathAsBytes)); }
Example #9
Source File: DoubleFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { DoubleFieldMapper.Builder builder = doubleField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = entry.getKey(); Object propNode = entry.getValue(); if (propName.equals("nullValue") || propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeDoubleValue(propNode)); iterator.remove(); } } return builder; }
Example #10
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 6 votes |
private static Map<String, Mapper.TypeParser> registerBuiltInMappers() { Map<String, Mapper.TypeParser> mapperParsers = new LinkedHashMap<>(); mapperParsers.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser()); mapperParsers.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser()); mapperParsers.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser()); mapperParsers.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser()); mapperParsers.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser()); mapperParsers.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser()); mapperParsers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser()); mapperParsers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser()); mapperParsers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser()); mapperParsers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser()); mapperParsers.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser()); mapperParsers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser()); mapperParsers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser()); mapperParsers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser()); mapperParsers.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser); mapperParsers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser()); mapperParsers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser()); return mapperParsers; }
Example #11
Source File: ShortFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ShortFieldMapper.Builder builder = shortField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeShortValue(propNode)); iterator.remove(); } } return builder; }
Example #12
Source File: FloatFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { FloatFieldMapper.Builder builder = floatField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeFloatValue(propNode)); iterator.remove(); } } return builder; }
Example #13
Source File: LongFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { LongFieldMapper.Builder builder = longField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeLongValue(propNode)); iterator.remove(); } } return builder; }
Example #14
Source File: IntegerFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { IntegerFieldMapper.Builder builder = integerField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeIntegerValue(propNode)); iterator.remove(); } } return builder; }
Example #15
Source File: ESTestCase.java From crate with Apache License 2.0 | 6 votes |
/** Creates an IndicesModule for testing with the given mappers and metadata mappers. */ public static IndicesModule newTestIndicesModule(Map<String, Mapper.TypeParser> extraMappers, Map<String, MetadataFieldMapper.TypeParser> extraMetadataMappers) { return new IndicesModule(Collections.singletonList( new MapperPlugin() { @Override public Map<String, Mapper.TypeParser> getMappers() { return extraMappers; } @Override public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() { return extraMetadataMappers; } } )); }
Example #16
Source File: ByteFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ByteFieldMapper.Builder builder = byteField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeByteValue(propNode)); iterator.remove(); } } return builder; }
Example #17
Source File: QueryParseContext.java From Elasticsearch with Apache License 2.0 | 6 votes |
private MappedFieldType failIfFieldMappingNotFound(String name, MappedFieldType fieldMapping) { if (fieldMapping != null || allowUnmappedFields) { return fieldMapping; } else if (mapUnmappedFieldAsString){ StringFieldMapper.Builder builder = MapperBuilders.stringField(name); // it would be better to pass the real index settings, but they are not easily accessible from here... Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexQueryParser.getIndexCreatedVersion()).build(); return builder.build(new Mapper.BuilderContext(settings, new ContentPath(1))).fieldType(); } else { Version indexCreatedVersion = indexQueryParser.getIndexCreatedVersion(); if (fieldMapping == null && indexCreatedVersion.onOrAfter(Version.V_1_4_0_Beta1)) { throw new QueryParsingException(this, "Strict field resolution and no field mapping can be found for the field with name [" + name + "]"); } else { return fieldMapping; } } }
Example #18
Source File: TypeParsers.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static void parseNumberField(NumberFieldMapper.Builder builder, String name, Map<String, Object> numberNode, Mapper.TypeParser.ParserContext parserContext) { parseField(builder, name, numberNode, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = numberNode.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("precision_step")) { builder.precisionStep(nodeIntegerValue(propNode)); iterator.remove(); } else if (propName.equals("ignore_malformed")) { builder.ignoreMalformed(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("coerce")) { builder.coerce(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("omit_norms")) { builder.omitNorms(nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("similarity")) { builder.similarity(parserContext.similarityLookupService().similarity(propNode.toString())); iterator.remove(); } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { iterator.remove(); } } }
Example #19
Source File: RootObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected ObjectMapper createMapper(String name, String fullPath, boolean enabled, Nested nested, Dynamic dynamic, ContentPath.Type pathType, Map<String, Mapper> mappers, @Nullable Settings settings) { assert !nested.isNested(); FormatDateTimeFormatter[] dates = null; if (dynamicDateTimeFormatters == null) { dates = new FormatDateTimeFormatter[0]; } else if (dynamicDateTimeFormatters.isEmpty()) { // add the default one dates = Defaults.DYNAMIC_DATE_TIME_FORMATTERS; } else { dates = dynamicDateTimeFormatters.toArray(new FormatDateTimeFormatter[dynamicDateTimeFormatters.size()]); } return new RootObjectMapper(name, enabled, dynamic, pathType, mappers, dates, dynamicTemplates.toArray(new DynamicTemplate[dynamicTemplates.size()]), dateDetection, numericDetection); }
Example #20
Source File: ParentFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { super.doMerge(mergeWith, updateAllTypes); ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith; if (Objects.equals(parentType, fieldMergeWith.parentType) == false) { throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]"); } List<String> conflicts = new ArrayList<>(); fieldType().checkCompatibility(fieldMergeWith.fieldType(), conflicts, true, false); // always strict, this cannot change parentJoinFieldType.checkCompatibility(fieldMergeWith.parentJoinFieldType, conflicts, true, false); // same here if (childJoinFieldType != null) { // TODO: this can be set to false when the old parent/child impl is removed, we can do eager global ordinals loading per type. childJoinFieldType.checkCompatibility(fieldMergeWith.childJoinFieldType, conflicts, updateAllTypes == false, false); } if (conflicts.isEmpty() == false) { throw new IllegalArgumentException("Merge conflicts: " + conflicts); } if (active()) { childJoinFieldType = fieldMergeWith.childJoinFieldType.clone(); } }
Example #21
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ObjectMapper merge(Mapper mergeWith, boolean updateAllTypes) { if (!(mergeWith instanceof ObjectMapper)) { throw new IllegalArgumentException("Can't merge a non object mapping [" + mergeWith.name() + "] with an object mapping [" + name() + "]"); } ObjectMapper mergeWithObject = (ObjectMapper) mergeWith; ObjectMapper merged = clone(); merged.doMerge(mergeWithObject, updateAllTypes); return merged; }
Example #22
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ObjectMapper.Builder builder = createBuilder(name); parseNested(name, node, builder); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = Strings.toUnderscoreCase(entry.getKey()); Object fieldNode = entry.getValue(); if (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder) || parseObjectProperties(name, fieldName, fieldNode, parserContext, builder)) { iterator.remove(); } } return builder; }
Example #23
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ObjectMapper unsetIncludeInAll() { if (includeInAll == null) { return this; } ObjectMapper clone = clone(); clone.includeInAll = null; // when called from outside, apply this on all the inner mappers for (Mapper mapper : mappers.values()) { if (mapper instanceof AllFieldMapper.IncludeInAll) { clone.putMapper(((AllFieldMapper.IncludeInAll) mapper).unsetIncludeInAll()); } } return clone; }
Example #24
Source File: RootObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Mapper.Builder findTemplateBuilder(ParseContext context, String name, String dynamicType, String matchType) { DynamicTemplate dynamicTemplate = findTemplate(context.path(), name, matchType); if (dynamicTemplate == null) { return null; } Mapper.TypeParser.ParserContext parserContext = context.docMapperParser().parserContext(name); String mappingType = dynamicTemplate.mappingType(dynamicType); Mapper.TypeParser typeParser = parserContext.typeParser(mappingType); if (typeParser == null) { throw new MapperParsingException("failed to find type parsed [" + mappingType + "] for [" + name + "]"); } return typeParser.parse(name, dynamicTemplate.mappingForName(name, dynamicType), parserContext); }
Example #25
Source File: CompletionFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public CompletionFieldMapper build(Mapper.BuilderContext context) { setupFieldType(context); CompletionFieldType completionFieldType = (CompletionFieldType) fieldType; completionFieldType.setProvider(new AnalyzingCompletionLookupProvider(preserveSeparators, false, preservePositionIncrements, payloads)); completionFieldType.setContextMapping(contextMapping); return new CompletionFieldMapper(name, fieldType, maxInputLength, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }
Example #26
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected void doMerge(final ObjectMapper mergeWith, boolean updateAllTypes) { if (nested().isNested()) { if (!mergeWith.nested().isNested()) { throw new IllegalArgumentException("object mapping [" + name() + "] can't be changed from nested to non-nested"); } } else { if (mergeWith.nested().isNested()) { throw new IllegalArgumentException("object mapping [" + name() + "] can't be changed from non-nested to nested"); } } if (mergeWith.dynamic != null) { this.dynamic = mergeWith.dynamic; } for (Mapper mergeWithMapper : mergeWith) { Mapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName()); Mapper merged; if (mergeIntoMapper == null) { // no mapping, simply add it merged = mergeWithMapper; } else { // root mappers can only exist here for backcompat, and are merged in Mapping merged = mergeIntoMapper.merge(mergeWithMapper, updateAllTypes); } putMapper(merged); } }
Example #27
Source File: RootObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
RootObjectMapper(String name, boolean enabled, Dynamic dynamic, ContentPath.Type pathType, Map<String, Mapper> mappers, FormatDateTimeFormatter[] dynamicDateTimeFormatters, DynamicTemplate dynamicTemplates[], boolean dateDetection, boolean numericDetection) { super(name, name, enabled, Nested.NO, dynamic, pathType, mappers); this.dynamicTemplates = dynamicTemplates; this.dynamicDateTimeFormatters = dynamicDateTimeFormatters; this.dateDetection = dateDetection; this.numericDetection = numericDetection; }
Example #28
Source File: BinaryFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { BinaryFieldMapper.Builder builder = binaryField(name); parseField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1) && (parserContext.parseFieldMatcher().match(fieldName, COMPRESS) || parserContext.parseFieldMatcher().match(fieldName, COMPRESS_THRESHOLD))) { iterator.remove(); } } return builder; }
Example #29
Source File: DateFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { DateFieldMapper.Builder builder = dateField(name); parseNumberField(builder, name, node, parserContext); boolean configuredFormat = false; for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(propNode.toString()); iterator.remove(); } else if (propName.equals("format")) { builder.dateTimeFormatter(parseDateTimeFormatter(propNode)); configuredFormat = true; iterator.remove(); } else if (propName.equals("numeric_resolution")) { builder.timeUnit(TimeUnit.valueOf(propNode.toString().toUpperCase(Locale.ROOT))); iterator.remove(); } else if (propName.equals("locale")) { builder.locale(LocaleUtils.parse(propNode.toString())); iterator.remove(); } } if (!configuredFormat) { if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) { builder.dateTimeFormatter(Defaults.DATE_TIME_FORMATTER); } else { builder.dateTimeFormatter(Defaults.DATE_TIME_FORMATTER_BEFORE_2_0); } } return builder; }
Example #30
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static MapperService newMapperService(Settings settings, Client client) { Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", System.getProperty("path.home")) .put("client.type", "node") .put(settings) .build(); Index index = new Index("test"); Injector parentInjector = new ModulesBuilder() .add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))) .createInjector(); AnalysisModule analysisModule = new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class)); new AnalysisBaseformPlugin(settings).onModule(analysisModule); Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), analysisModule) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); return new MapperService(new Index("test"), indexSettings, analysisService, similarityLookupService, null, mapperRegistry); }