protected Explicit<Boolean> ignoreMalformed(BuilderContext context) { if (ignoreMalformed != null) { return new Explicit<>(ignoreMalformed, true); } if (context.indexSettings() != null) { return new Explicit<>(IGNORE_MALFORMED_SETTING.get(context.indexSettings()), false); } return Defaults.IGNORE_MALFORMED; }
protected Explicit<Boolean> coerce(BuilderContext context) { if (coerce != null) { return new Explicit<>(coerce, true); } if (context.indexSettings() != null) { return new Explicit<>( context.indexSettings().getAsBoolean("index.mapping.coerce", Defaults.COERCE.value()), false); } return Defaults.COERCE; }
@Override public PercolatorFieldMapper build(BuilderContext context) { context.path().add(name()); FieldType fieldType = (FieldType) this.fieldType; KeywordFieldMapper extractedTermsField = createExtractQueryFieldBuilder(EXTRACTED_TERMS_FIELD_NAME, context); fieldType.queryTermsField = extractedTermsField.fieldType(); KeywordFieldMapper extractionResultField = createExtractQueryFieldBuilder(EXTRACTION_RESULT_FIELD_NAME, context); fieldType.extractionResultField = extractionResultField.fieldType(); BinaryFieldMapper queryBuilderField = createQueryBuilderFieldBuilder(context); fieldType.queryBuilderField = queryBuilderField.fieldType(); context.path().remove(); setupFieldType(context); return new PercolatorFieldMapper( name(), fieldType, defaultFieldType, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo, queryShardContext, extractedTermsField, extractionResultField, queryBuilderField); }
@Override public DateFieldMapper build(BuilderContext context) { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); if (!locale.equals(dateTimeFormatter.locale())) { dateTimeFormatter = new FormatDateTimeFormatter( dateTimeFormatter.format(), dateTimeFormatter.parser(), dateTimeFormatter.printer(), locale); } DateFieldMapper fieldMapper = new DateFieldMapper( buildNames(context), dateTimeFormatter, fieldType.numericPrecisionStep(), boost, fieldType, docValues, nullValue, timeUnit, ignoreMalformed(context), coerce(context), postingsProvider, docValuesProvider, similarity, normsLoading, fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); fieldMapper.includeInAll(includeInAll); return fieldMapper; }
@Override public ExternalMapper build(BuilderContext context) { context.path().add(name); BinaryFieldMapper binMapper = binBuilder.build(context); BooleanFieldMapper boolMapper = boolBuilder.build(context); BaseGeoPointFieldMapper pointMapper = latLonPointBuilder.build(context); GeoShapeFieldMapper shapeMapper = shapeBuilder.build(context); FieldMapper stringMapper = (FieldMapper) stringBuilder.build(context); context.path().remove(); setupFieldType(context); return new ExternalMapper( name, fieldType, generatedValue, mapperName, binMapper, boolMapper, pointMapper, shapeMapper, stringMapper, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }
@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.includeInAllIfNotSet(includeInAll); return (Y) objectMapper; }
@Override public FieldNamesFieldMapper build(BuilderContext context) { setupFieldType(context); FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldType) fieldType; fieldNamesFieldType.setEnabled(enabled); return new FieldNamesFieldMapper(fieldType, fieldDataSettings, context.indexSettings()); }
@Override public SizeFieldMapper build(BuilderContext context) { return new SizeFieldMapper( enabledState, fieldType, postingsProvider, docValuesProvider, fieldDataSettings, context.indexSettings()); }
@Override public ParentFieldMapper build(BuilderContext context) { if (parentType == null) { throw new MapperParsingException("[_parent] field mapping must contain the [type] option"); } parentJoinFieldType.setName(joinField(documentType)); parentJoinFieldType.setFieldDataType(null); childJoinFieldType.setName(joinField(parentType)); return new ParentFieldMapper( fieldType, parentJoinFieldType, childJoinFieldType, parentType, context.indexSettings()); }
@Override public BooleanFieldMapper build(BuilderContext context) { setupFieldType(context); return new BooleanFieldMapper( name, fieldType, docValues, fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }
@Override public TTLFieldMapper build(BuilderContext context) { setupFieldType(context); return new TTLFieldMapper( fieldType, enabledState, defaultTTL, ignoreMalformed(context), coerce(context), fieldDataSettings, context.indexSettings()); }
@Override public TypeFieldMapper build(BuilderContext context) { return new TypeFieldMapper( name, indexName, boost, fieldType, postingsProvider, docValuesProvider, fieldDataSettings, context.indexSettings()); }
@Override public IdFieldMapper build(BuilderContext context) { return new IdFieldMapper( name, indexName, boost, fieldType, docValues, path, fieldDataSettings, context.indexSettings()); }
@Override public IpFieldMapper build(BuilderContext context) { setupFieldType(context); IpFieldMapper fieldMapper = new IpFieldMapper( name, fieldType, defaultFieldType, ignoreMalformed(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); return (IpFieldMapper) fieldMapper.includeInAll(includeInAll); }
@Override public OntologyMapper build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); Map<String, FieldMapper<String>> fieldMappers = Maps.newHashMap(); context.path().add(name); if (propertyBuilders != null) { for (String property : propertyBuilders.keySet()) { StringFieldMapper sfm = propertyBuilders.get(property).build(context); fieldMappers.put(sfm.names().indexName(), sfm); } } // Initialise field mappers for the pre-defined fields for (FieldMappings mapping : ontologySettings.getFieldMappings()) { if (!fieldMappers.containsKey(context.path().fullPathAsText(mapping.getFieldName()))) { StringFieldMapper mapper = MapperBuilders.stringField(mapping.getFieldName()) .store(true) .index(true) .tokenized(!mapping.isUriField()) .build(context); fieldMappers.put(mapper.names().indexName(), mapper); } } context.path().remove(); // remove name context.path().pathType(origPathType); return new OntologyMapper( buildNames(context), fieldType, docValues, indexAnalyzer, searchAnalyzer, postingsProvider, docValuesProvider, similarity, fieldDataSettings, context.indexSettings(), new MultiFields.Builder().build(this, context), ontologySettings, fieldMappers, threadPool); }
@Override public ShortFieldMapper build(BuilderContext context) { setupFieldType(context); ShortFieldMapper fieldMapper = new ShortFieldMapper( fieldType, docValues, ignoreMalformed(context), coerce(context), fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); fieldMapper.includeInAll(includeInAll); return fieldMapper; }
@Override public StringFieldMapper build(BuilderContext context) { if (positionOffsetGap > 0) { indexAnalyzer = new NamedAnalyzer(indexAnalyzer, positionOffsetGap); searchAnalyzer = new NamedAnalyzer(searchAnalyzer, positionOffsetGap); searchQuotedAnalyzer = new NamedAnalyzer(searchQuotedAnalyzer, positionOffsetGap); } // if the field is not analyzed, then by default, we should omit norms and have docs only // index options, as probably what the user really wants // if they are set explicitly, we will use those values // we also change the values on the default field type so that toXContent emits what // differs from the defaults FieldType defaultFieldType = new FieldType(Defaults.FIELD_TYPE); if (fieldType.indexOptions() != IndexOptions.NONE && !fieldType.tokenized()) { defaultFieldType.setOmitNorms(true); defaultFieldType.setIndexOptions(IndexOptions.DOCS); if (!omitNormsSet && boost == Defaults.BOOST) { fieldType.setOmitNorms(true); } if (!indexOptionsSet) { fieldType.setIndexOptions(IndexOptions.DOCS); } } defaultFieldType.freeze(); StringFieldMapper fieldMapper = new StringFieldMapper( buildNames(context), boost, fieldType, defaultFieldType, docValues, nullValue, indexAnalyzer, searchAnalyzer, searchQuotedAnalyzer, positionOffsetGap, ignoreAbove, similarity, normsLoading, fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); fieldMapper.includeInAll(includeInAll); return fieldMapper; }
@Override public LegacyShortFieldMapper build(BuilderContext context) { if (context.indexCreatedVersion().onOrAfter(Version.V_5_0_0_alpha2)) { throw new IllegalStateException("Cannot use legacy numeric types after 5.0"); } setupFieldType(context); return new LegacyShortFieldMapper( name, fieldType, defaultFieldType, ignoreMalformed(context), coerce(context), includeInAll, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }
@Override public ByteFieldMapper build(BuilderContext context) { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); ByteFieldMapper fieldMapper = new ByteFieldMapper( buildNames(context), precisionStep, boost, fieldType, nullValue, ignoreMalformed(context), postingsProvider, docValuesProvider, similarity, fieldDataSettings, context.indexSettings()); fieldMapper.includeInAll(includeInAll); return fieldMapper; }
@Override public AllFieldMapper build(BuilderContext context) { // In case the mapping overrides these fieldType.setIndexed(true); fieldType.setTokenized(true); return new AllFieldMapper( name, fieldType, indexAnalyzer, searchAnalyzer, enabled, autoBoost, postingsProvider, docValuesProvider, similarity, normsLoading, fieldDataSettings, context.indexSettings()); }
@Override public TextFieldMapper build(BuilderContext context) { if (positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) { fieldType.setIndexAnalyzer( new NamedAnalyzer(fieldType.indexAnalyzer(), positionIncrementGap)); fieldType.setSearchAnalyzer( new NamedAnalyzer(fieldType.searchAnalyzer(), positionIncrementGap)); fieldType.setSearchQuoteAnalyzer( new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap)); } setupFieldType(context); TextFieldMapper fieldMapper = new TextFieldMapper( name, fieldType, defaultFieldType, positionIncrementGap, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); return fieldMapper.includeInAll(includeInAll); }
@Override public StringFieldMapper build(BuilderContext context) { if (positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) { fieldType.setIndexAnalyzer( new NamedAnalyzer(fieldType.indexAnalyzer(), positionIncrementGap)); fieldType.setSearchAnalyzer( new NamedAnalyzer(fieldType.searchAnalyzer(), positionIncrementGap)); fieldType.setSearchQuoteAnalyzer( new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap)); } // if the field is not analyzed, then by default, we should omit norms and have docs only // index options, as probably what the user really wants // if they are set explicitly, we will use those values // we also change the values on the default field type so that toXContent emits what // differs from the defaults if (fieldType.indexOptions() != IndexOptions.NONE && !fieldType.tokenized()) { defaultFieldType.setOmitNorms(true); defaultFieldType.setIndexOptions(IndexOptions.DOCS); if (!omitNormsSet && fieldType.boost() == 1.0f) { fieldType.setOmitNorms(true); } if (!indexOptionsSet) { fieldType.setIndexOptions(IndexOptions.DOCS); } } setupFieldType(context); StringFieldMapper fieldMapper = new StringFieldMapper( name, fieldType, defaultFieldType, positionIncrementGap, ignoreAbove, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); return fieldMapper.includeInAll(includeInAll); }
@Override public GeoShapeFieldMapper build(BuilderContext context) { GeoShapeFieldType geoShapeFieldType = (GeoShapeFieldType) fieldType; if (geoShapeFieldType.tree.equals(Names.TREE_QUADTREE) && context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) { geoShapeFieldType.setTree("legacyquadtree"); } if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1) || (geoShapeFieldType.treeLevels() == 0 && geoShapeFieldType.precisionInMeters() < 0)) { geoShapeFieldType.setDefaultDistanceErrorPct(Defaults.LEGACY_DISTANCE_ERROR_PCT); } setupFieldType(context); return new GeoShapeFieldMapper( name, fieldType, coerce(context), context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }
@Override public IntegerFieldMapper build(BuilderContext context) { fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f); IntegerFieldMapper fieldMapper = new IntegerFieldMapper( buildNames(context), fieldType.numericPrecisionStep(), boost, fieldType, docValues, nullValue, ignoreMalformed(context), coerce(context), postingsProvider, docValuesProvider, similarity, normsLoading, fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); fieldMapper.includeInAll(includeInAll); return fieldMapper; }
@Override public GeoPointFieldMapper build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); DoubleFieldMapper latMapper = null; DoubleFieldMapper lonMapper = null; GeoPointFieldType geoPointFieldType = (GeoPointFieldType) fieldType; context.path().add(name); if (enableLatLon) { NumberFieldMapper.Builder<?, ?> latMapperBuilder = doubleField(Names.LAT).includeInAll(false); NumberFieldMapper.Builder<?, ?> lonMapperBuilder = doubleField(Names.LON).includeInAll(false); if (precisionStep != null) { latMapperBuilder.precisionStep(precisionStep); lonMapperBuilder.precisionStep(precisionStep); } latMapper = (DoubleFieldMapper) latMapperBuilder .includeInAll(false) .store(fieldType.stored()) .docValues(false) .build(context); lonMapper = (DoubleFieldMapper) lonMapperBuilder .includeInAll(false) .store(fieldType.stored()) .docValues(false) .build(context); geoPointFieldType.setLatLonEnabled(latMapper.fieldType(), lonMapper.fieldType()); } StringFieldMapper geohashMapper = null; if (enableGeoHash || enableGeohashPrefix) { // TODO: possible also implicitly enable geohash if geohash precision is set geohashMapper = stringField(Names.GEOHASH) .index(true) .tokenized(false) .includeInAll(false) .omitNorms(true) .indexOptions(IndexOptions.DOCS) .build(context); geoPointFieldType.setGeohashEnabled( geohashMapper.fieldType(), geoHashPrecision, enableGeohashPrefix); } context.path().remove(); context.path().pathType(origPathType); // this is important: even if geo points feel like they need to be tokenized to distinguish // lat from lon, we actually want to // store them as a single token. fieldType.setTokenized(false); setupFieldType(context); fieldType.setHasDocValues(false); defaultFieldType.setHasDocValues(false); return new GeoPointFieldMapper( name, fieldType, defaultFieldType, context.indexSettings(), origPathType, latMapper, lonMapper, geohashMapper, multiFieldsBuilder.build(this, context)); }
@Override public RoutingFieldMapper build(BuilderContext context) { return new RoutingFieldMapper( fieldType, required, path, fieldDataSettings, context.indexSettings()); }
@Override public IdFieldMapper build(BuilderContext context) { setupFieldType(context); return new IdFieldMapper(fieldType, path, context.indexSettings()); }
@Override public SizeFieldMapper build(BuilderContext context) { setupFieldType(context); fieldType.setHasDocValues(false); return new SizeFieldMapper(enabledState, fieldType, context.indexSettings()); }
@Override public TokenFieldMapper build(BuilderContext context) { return new TokenFieldMapper(context.indexSettings()); }
@Override public UidFieldMapper build(BuilderContext context) { setupFieldType(context); fieldType.setHasDocValues(context.indexCreatedVersion().before(Version.V_2_0_0_beta1)); return new UidFieldMapper(fieldType, defaultFieldType, context.indexSettings()); }