@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(); }
/** * Merge changes coming from {@code mergeWith} in place. * @param updateAllTypes TODO */ protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { if (!this.getClass().equals(mergeWith.getClass())) { String mergedType = mergeWith.getClass().getSimpleName(); if (mergeWith instanceof FieldMapper) { mergedType = ((FieldMapper) mergeWith).contentType(); } throw new IllegalArgumentException("mapper [" + fieldType().names().fullName() + "] of different type, current_type [" + contentType() + "], merged_type [" + mergedType + "]"); } FieldMapper fieldMergeWith = (FieldMapper) mergeWith; multiFields = multiFields.merge(fieldMergeWith.multiFields); // apply changeable values this.fieldType = fieldMergeWith.fieldType; this.copyTo = fieldMergeWith.copyTo; }
multiFields.parse(this, context); } else { String currentFieldName = null;
multiFields.parse(this, context); } else { String currentFieldName = null;
context.doc().add(field); multiFields.parse(this, context); return null;
multiFields.parse(this, externalValueContext);
multiFields.toXContent(builder, params);
builder.field("fielddata", fieldType().fieldDataType().getSettings().getAsMap()); multiFields.toXContent(builder, params);
multiFields.parse(this, context); return null;
multiFields.toXContent(builder, params); copyTo.toXContent(builder, params);
@Override public void parse(ParseContext originalContext, GeoPoint point, String geoHash) throws IOException { // Geopoint fields, by default, will not be included in _all final ParseContext context = originalContext.setIncludeInAllDefault(false); if (ignoreMalformed.value() == false) { if (point.lat() > 90.0 || point.lat() < -90.0) { throw new IllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name()); } if (point.lon() > 180.0 || point.lon() < -180) { throw new IllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name()); } } else { GeoUtils.normalizePoint(point); } if (fieldType().indexOptions() != IndexOptions.NONE) { context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon())); } if (fieldType().stored()) { context.doc().add(new StoredField(fieldType().name(), point.toString())); } if (fieldType.hasDocValues()) { context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon())); } // if the mapping contains multifields then use the geohash string if (multiFields.iterator().hasNext()) { multiFields.parse(this, context.createExternalValueContext(point.geohash())); } } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE, CONTENT_TYPE); builder.field(Fields.ANALYZER, fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PAYLOADS, fieldType().analyzingSuggestLookupProvider.hasPayloads()); builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreservePositionsIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); multiFields.toXContent(builder, params); if (fieldType().requiresContext()) { builder.startObject(Fields.CONTEXT); for (ContextMapping mapping : fieldType().getContextMapping().values()) { builder.value(mapping); } builder.endObject(); } return builder.endObject(); }
public MultiFields merge(MultiFields mergeWith) { if (pathType != mergeWith.pathType) { throw new IllegalArgumentException("Can't change path type from [" + pathType + "] to [" + mergeWith.pathType + "]"); } ImmutableOpenMap.Builder<String, FieldMapper> newMappersBuilder = ImmutableOpenMap.builder(mappers); for (ObjectCursor<FieldMapper> cursor : mergeWith.mappers.values()) { FieldMapper mergeWithMapper = cursor.value; FieldMapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName()); if (mergeIntoMapper == null) { // we disable the all in multi-field mappers if (mergeWithMapper instanceof AllFieldMapper.IncludeInAll) { mergeWithMapper = (FieldMapper) ((AllFieldMapper.IncludeInAll) mergeWithMapper).unsetIncludeInAll(); } newMappersBuilder.put(mergeWithMapper.simpleName(), mergeWithMapper); } else { FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper, false); newMappersBuilder.put(merged.simpleName(), merged); // override previous definition } } ImmutableOpenMap<String, FieldMapper> mappers = newMappersBuilder.build(); return new MultiFields(pathType, mappers); }
@SuppressWarnings("unchecked") public MultiFields build(FieldMapper.Builder mainFieldBuilder, BuilderContext context) { if (pathType == ContentPath.Type.FULL && mapperBuilders.isEmpty()) { return empty(); } else if (mapperBuilders.isEmpty()) { return new MultiFields(pathType, ImmutableOpenMap.<String, FieldMapper>of()); } else { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); context.path().add(mainFieldBuilder.name()); ImmutableOpenMap.Builder mapperBuilders = this.mapperBuilders; for (ObjectObjectCursor<String, Mapper.Builder> cursor : this.mapperBuilders) { String key = cursor.key; Mapper.Builder value = cursor.value; Mapper mapper = value.build(context); assert mapper instanceof FieldMapper; mapperBuilders.put(key, mapper); } context.path().remove(); context.path().pathType(origPathType); ImmutableOpenMap.Builder<String, FieldMapper> mappers = mapperBuilders.cast(); return new MultiFields(pathType, mappers.build()); } } }
/** * Parse using the provided {@link ParseContext} and return a mapping * update if dynamic mappings modified the mappings, or {@code null} if * mappings were not modified. */ public Mapper parse(ParseContext context) throws IOException { final List<Field> fields = new ArrayList<>(2); try { parseCreateField(context, fields); for (Field field : fields) { if (!customBoost()) { field.setBoost(fieldType().boost()); } context.doc().add(field); } } catch (Exception e) { throw new MapperParsingException("failed to parse [" + fieldType().names().fullName() + "]", e); } multiFields.parse(this, context); return null; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE, CONTENT_TYPE); builder.field(Fields.ANALYZER, fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PAYLOADS, fieldType().analyzingSuggestLookupProvider.hasPayloads()); builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreservePositionsIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); multiFields.toXContent(builder, params); if (fieldType().requiresContext()) { builder.startObject(Fields.CONTEXT); for (ContextMapping mapping : fieldType().getContextMapping().values()) { builder.value(mapping); } builder.endObject(); } return builder.endObject(); }
@Override public FieldMapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldType) { final MappedFieldType newFieldType = fullNameToFieldType.get(fieldType.name()); if (newFieldType == null) { // this field does not exist in the mappings yet // this can happen if this mapper represents a mapping update return this; } else if (fieldType.getClass() != newFieldType.getClass()) { throw new IllegalStateException("Mixing up field types: " + fieldType.getClass() + " != " + newFieldType.getClass() + " on field " + fieldType.name()); } MultiFields updatedMultiFields = multiFields.updateFieldType(fullNameToFieldType); if (fieldType == newFieldType && multiFields == updatedMultiFields) { return this; // no change } FieldMapper updated = clone(); updated.fieldType = newFieldType; updated.multiFields = updatedMultiFields; return updated; }