private static MappedFieldType defaultFieldType(Settings indexSettings) { MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); Version indexCreated = Version.indexCreated(indexSettings); if (indexCreated.before(Version.V_2_1_0)) { // enables fielddata loading, doc values was disabled on _type between 2.0 and 2.1. ((TypeFieldType) defaultFieldType).setFielddata(true); } else { defaultFieldType.setHasDocValues(true); } return defaultFieldType; }
/** * We only allow upto 1 percolator field per index. * * <p>Reasoning here is that the PercolatorQueryCache only supports a single document having a * percolator query. Also specifying multiple queries per document feels like an anti pattern */ private void checkPercolatorFieldLimit(Iterable<MappedFieldType> fieldTypes) { List<String> percolatorFieldTypes = new ArrayList<>(); for (MappedFieldType fieldType : fieldTypes) { if (fieldType instanceof PercolatorFieldMapper.PercolatorFieldType) { percolatorFieldTypes.add(fieldType.name()); } } if (percolatorFieldTypes.size() > 1) { throw new IllegalArgumentException( "Up to one percolator field type is allowed per index, " + "found the following percolator fields [" + percolatorFieldTypes + "]"); } }
static { FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); FIELD_TYPE.setTokenized(false); FIELD_TYPE.setStored(false); FIELD_TYPE.setOmitNorms(true); FIELD_TYPE.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); FIELD_TYPE.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER); FIELD_TYPE.setName(NAME); FIELD_TYPE.freeze(); }
private static Mapper.Builder<?, ?> createBuilderFromFieldType( final ParseContext context, MappedFieldType fieldType, String currentFieldName) { Mapper.Builder builder = null; if (fieldType instanceof StringFieldType) { builder = context.root().findTemplateBuilder(context, currentFieldName, "string"); if (builder == null) { builder = MapperBuilders.stringField(currentFieldName); } } else if (fieldType instanceof DateFieldType) { builder = context.root().findTemplateBuilder(context, currentFieldName, "date"); if (builder == null) { builder = MapperBuilders.dateField(currentFieldName); } } else if (fieldType.numericType() != null) { switch (fieldType.numericType()) { case LONG: builder = context.root().findTemplateBuilder(context, currentFieldName, "long"); if (builder == null) { builder = MapperBuilders.longField(currentFieldName); } break; case DOUBLE: builder = context.root().findTemplateBuilder(context, currentFieldName, "double"); if (builder == null) { builder = MapperBuilders.doubleField(currentFieldName); } break; case INT: builder = context.root().findTemplateBuilder(context, currentFieldName, "integer"); if (builder == null) { builder = MapperBuilders.integerField(currentFieldName); } break; case FLOAT: builder = context.root().findTemplateBuilder(context, currentFieldName, "float"); if (builder == null) { builder = MapperBuilders.floatField(currentFieldName); } break; default: throw new AssertionError("Unexpected numeric type " + fieldType.numericType()); } } return builder; }
static { FIELD_TYPE.freeze(); }
private static ObjectMapper parseDynamicValue( final ParseContext context, ObjectMapper parentMapper, String currentFieldName, XContentParser.Token token) throws IOException { ObjectMapper.Dynamic dynamic = parentMapper.dynamic(); if (dynamic == null) { dynamic = dynamicOrDefault(context.root().dynamic()); } if (dynamic == ObjectMapper.Dynamic.STRICT) { throw new StrictDynamicMappingException(parentMapper.fullPath(), currentFieldName); } if (dynamic == ObjectMapper.Dynamic.FALSE) { return null; } final Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path()); final MappedFieldType existingFieldType = context.mapperService().fullName(context.path().pathAsText(currentFieldName)); Mapper.Builder builder = null; if (existingFieldType != null) { // create a builder of the same type builder = createBuilderFromFieldType(context, existingFieldType, currentFieldName); if (builder != null) { // best-effort to not introduce a conflict if (builder instanceof StringFieldMapper.Builder) { StringFieldMapper.Builder stringBuilder = (StringFieldMapper.Builder) builder; stringBuilder.fieldDataSettings(existingFieldType.fieldDataType().getSettings()); stringBuilder.store(existingFieldType.stored()); stringBuilder.indexOptions(existingFieldType.indexOptions()); stringBuilder.tokenized(existingFieldType.tokenized()); stringBuilder.omitNorms(existingFieldType.omitNorms()); stringBuilder.docValues(existingFieldType.hasDocValues()); stringBuilder.indexAnalyzer(existingFieldType.indexAnalyzer()); stringBuilder.searchAnalyzer(existingFieldType.searchAnalyzer()); } else if (builder instanceof NumberFieldMapper.Builder) { NumberFieldMapper.Builder<?, ?> numberBuilder = (NumberFieldMapper.Builder<?, ?>) builder; numberBuilder.fieldDataSettings(existingFieldType.fieldDataType().getSettings()); numberBuilder.store(existingFieldType.stored()); numberBuilder.indexOptions(existingFieldType.indexOptions()); numberBuilder.tokenized(existingFieldType.tokenized()); numberBuilder.omitNorms(existingFieldType.omitNorms()); numberBuilder.docValues(existingFieldType.hasDocValues()); numberBuilder.precisionStep(existingFieldType.numericPrecisionStep()); } } } if (builder == null) { builder = createBuilderFromDynamicValue(context, token, currentFieldName); } Mapper mapper = builder.build(builderContext); mapper = parseAndMergeUpdate(mapper, context); ObjectMapper update = null; if (mapper != null) { update = parentMapper.mappingUpdate(mapper); } return update; }
public Analyzer apply(MappedFieldType fieldType) { return fieldType.indexAnalyzer(); }
public Analyzer apply(MappedFieldType fieldType) { return fieldType.searchQuoteAnalyzer(); }
private TypeFieldMapper(Settings indexSettings, MappedFieldType existing) { this(existing == null ? defaultFieldType(indexSettings) : existing.clone(), indexSettings); }
@Override public AttachmentMapper build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); FieldMapper contentMapper; if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) { // old behavior, we need the content to be indexed under the attachment field name if (contentBuilder instanceof FieldMapper.Builder == false) { throw new IllegalStateException("content field for attachment must be a field mapper"); } ((FieldMapper.Builder) contentBuilder).indexName(name); contentBuilder.name = name + "." + FieldNames.CONTENT; contentMapper = (FieldMapper) contentBuilder.build(context); context.path().add(name); } else { context.path().add(name); contentMapper = (FieldMapper) contentBuilder.build(context); } FieldMapper dateMapper = (FieldMapper) dateBuilder.build(context); FieldMapper authorMapper = (FieldMapper) authorBuilder.build(context); FieldMapper titleMapper = (FieldMapper) titleBuilder.build(context); FieldMapper nameMapper = (FieldMapper) nameBuilder.build(context); FieldMapper keywordsMapper = (FieldMapper) keywordsBuilder.build(context); FieldMapper contentTypeMapper = (FieldMapper) contentTypeBuilder.build(context); FieldMapper contentLength = (FieldMapper) contentLengthBuilder.build(context); FieldMapper language = (FieldMapper) languageBuilder.build(context); context.path().remove(); context.path().pathType(origPathType); if (defaultIndexedChars == null && context.indexSettings() != null) { defaultIndexedChars = context.indexSettings().getAsInt("index.mapping.attachment.indexed_chars", 100000); } if (defaultIndexedChars == null) { defaultIndexedChars = 100000; } if (ignoreErrors == null && context.indexSettings() != null) { ignoreErrors = context .indexSettings() .getAsBoolean("index.mapping.attachment.ignore_errors", Boolean.TRUE); } if (ignoreErrors == null) { ignoreErrors = Boolean.TRUE; } if (langDetect == null && context.indexSettings() != null) { langDetect = context .indexSettings() .getAsBoolean("index.mapping.attachment.detect_language", Boolean.FALSE); } if (langDetect == null) { langDetect = Boolean.FALSE; } MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); if (this.fieldType.indexOptions() != IndexOptions.NONE && !this.fieldType.tokenized()) { defaultFieldType.setOmitNorms(true); defaultFieldType.setIndexOptions(IndexOptions.DOCS); if (!this.omitNormsSet && this.fieldType.boost() == 1.0F) { this.fieldType.setOmitNorms(true); } if (!this.indexOptionsSet) { this.fieldType.setIndexOptions(IndexOptions.DOCS); } } defaultFieldType.freeze(); this.setupFieldType(context); return new AttachmentMapper( name, fieldType, defaultFieldType, pathType, defaultIndexedChars, ignoreErrors, langDetect, contentMapper, dateMapper, titleMapper, nameMapper, authorMapper, keywordsMapper, contentTypeMapper, contentLength, language, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); }