private SourceFieldMapper(boolean enabled, String[] includes, String[] excludes, Settings indexSettings) { super(NAME, Defaults.FIELD_TYPE.clone(), Defaults.FIELD_TYPE, indexSettings); // Only stored. this.enabled = enabled; this.includes = includes; this.excludes = excludes; final boolean filtered = (includes != null && includes.length > 0) || (excludes != null && excludes.length > 0); this.filter = enabled && filtered && fieldType().stored() ? XContentMapValues.filter(includes, excludes) : null; this.complete = enabled && includes == null && excludes == null; }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) { Field uid = new Field(NAME, Uid.createUid(context.sourceToParse().type(), context.sourceToParse().id()), fieldType); fields.add(uid); } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) { if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { BytesRef id = Uid.encodeId(context.sourceToParse().id()); fields.add(new Field(NAME, id, fieldType)); } else { fields.add(new Field(NAME, context.sourceToParse().id(), fieldType)); } } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { String routing = context.sourceToParse().routing(); if (routing != null) { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { fields.add(new Field(fieldType().name(), routing, fieldType())); createFieldNamesField(context, fields); } } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) { return; } fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); if (fieldType().hasDocValues()) { fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type()))); } }
/** * Load field values for highlighting. */ public static List<Object> loadFieldValues(SearchContextHighlight.Field field, MappedFieldType fieldType, SearchContext searchContext, FetchSubPhase.HitContext hitContext) throws IOException { //percolator needs to always load from source, thus it sets the global force source to true boolean forceSource = searchContext.highlight().forceSource(field); List<Object> textsToHighlight; if (!forceSource && fieldType.stored()) { CustomFieldsVisitor fieldVisitor = new CustomFieldsVisitor(singleton(fieldType.name()), false); hitContext.reader().document(hitContext.docId(), fieldVisitor); textsToHighlight = fieldVisitor.fields().get(fieldType.name()); if (textsToHighlight == null) { // Can happen if the document doesn't have the field to highlight textsToHighlight = Collections.emptyList(); } } else { SourceLookup sourceLookup = searchContext.lookup().source(); sourceLookup.setSegmentAndDocument(hitContext.readerContext(), hitContext.docId()); textsToHighlight = sourceLookup.extractRawValues(fieldType.name()); } assert textsToHighlight != null; return textsToHighlight; }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { BytesReference originalSource = context.sourceToParse().source(); BytesReference source = originalSource; if (enabled && fieldType().stored() && source != null) { // Percolate and tv APIs may not set the source and that is ok, because these APIs will not index any data if (filter != null) { // we don't update the context source if we filter, we want to keep it as is... Tuple<XContentType, Map<String, Object>> mapTuple = XContentHelper.convertToMap(source, true, context.sourceToParse().getXContentType()); Map<String, Object> filteredSource = filter.apply(mapTuple.v2()); BytesStreamOutput bStream = new BytesStreamOutput(); XContentType contentType = mapTuple.v1(); XContentBuilder builder = XContentFactory.contentBuilder(contentType, bStream).map(filteredSource); builder.close(); source = bStream.bytes(); } BytesRef ref = source.toBytesRef(); fields.add(new StoredField(fieldType().name(), ref.bytes, ref.offset, ref.length)); } else { source = null; } if (originalSource != null && source != originalSource && context.indexSettings().isSoftDeleteEnabled()) { // if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery BytesRef ref = originalSource.toBytesRef(); fields.add(new StoredField(RECOVERY_SOURCE_NAME, ref.bytes, ref.offset, ref.length)); fields.add(new NumericDocValuesField(RECOVERY_SOURCE_NAME, 1)); } }
context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon())); if (fieldType().stored()) { context.doc().add(new StoredField(fieldType().name(), point.toString())); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { List<IndexableField> fields = new ArrayList<>(1); createFieldNamesField(context, fields);
boolean stored = fieldType.stored(); fields.addAll(fieldType().rangeType.createFields(context, name(), range, indexed, docValued, stored)); if (docValued == false && (indexed || stored)) {
fragListBuilder = new SingleFragListBuilder(); if (!forceSource && fieldType.stored()) { fragmentsBuilder = new SimpleFragmentsBuilder(fieldType, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner); new SimpleFragListBuilder() : new SimpleFragListBuilder(field.fieldOptions().fragmentOffset()); if (field.fieldOptions().scoreOrdered()) { if (!forceSource && fieldType.stored()) { fragmentsBuilder = new ScoreOrderFragmentsBuilder(field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner); if (!forceSource && fieldType.stored()) { fragmentsBuilder = new SimpleFragmentsBuilder(fieldType, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) { Field uid = new Field(NAME, Uid.createUid(context.sourceToParse().type(), context.sourceToParse().id()), fieldType); fields.add(uid); } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) { if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { BytesRef id = Uid.encodeId(context.sourceToParse().id()); fields.add(new Field(NAME, id, fieldType)); } else { fields.add(new Field(NAME, context.sourceToParse().id(), fieldType)); } } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { String routing = context.sourceToParse().routing(); if (routing != null) { if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { fields.add(new Field(fieldType().name(), routing, fieldType())); createFieldNamesField(context, fields); } } }
@Override public void createField(ParseContext context, Object _id) throws IOException { String id = (String) _id; //context.sourceToParse().id(id); if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { context.doc().add(new Field(fieldType().name(), context.sourceToParse().id(), fieldType())); } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) { return; } fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); if (fieldType().hasDocValues()) { fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type()))); } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) { return; } fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); if (fieldType().hasDocValues()) { fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type()))); } }