private static boolean isValidField(MappedFieldType fieldType) { // must be a string if (fieldType instanceof KeywordFieldMapper.KeywordFieldType == false && fieldType instanceof TextFieldMapper.TextFieldType == false) { return false; } // and must be indexed if (fieldType.indexOptions() == IndexOptions.NONE) { return false; } return true; }
/** Returns true if the field is searchable. * */ public boolean isSearchable() { return indexOptions() != IndexOptions.NONE; }
protected KeywordFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, int ignoreAbove, Boolean includeInAll, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); assert fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) <= 0; this.ignoreAbove = ignoreAbove; this.includeInAll = includeInAll; }
private boolean hasPositions(MappedFieldType fieldType) { return fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; }
protected final void failIfNotIndexed() { if (indexOptions() == IndexOptions.NONE && pointDataDimensionCount() == 0) { // we throw an IAE rather than an ISE so that it translates to a 4xx code rather than 5xx code on the http layer throw new IllegalArgumentException("Cannot search on field [" + name() + "] since it is not indexed."); } }
protected OffsetSource getOffsetSource(MappedFieldType fieldType) { if (fieldType.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) { return fieldType.storeTermVectors() ? OffsetSource.POSTINGS_WITH_TERM_VECTORS : OffsetSource.POSTINGS; } if (fieldType.storeTermVectorOffsets()) { return OffsetSource.TERM_VECTORS; } return OffsetSource.ANALYSIS; } }
public final boolean includeInAll(Boolean includeInAll, FieldMapper mapper) { return includeInAll(includeInAll, mapper.fieldType().indexOptions() != IndexOptions.NONE); }
protected boolean defaultDocValues(Version indexCreated) { if (indexCreated.onOrAfter(Version.V_5_0_0_alpha1)) { // add doc values by default to keyword (boolean, numerics, etc.) fields return fieldType.tokenized() == false; } else { return fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE; } }
public T index(boolean index) { if (index) { if (fieldType.indexOptions() == IndexOptions.NONE) { /* * the logic here is to reset to the default options only if we are not indexed ie. options are null * if the fieldType has a non-null option we are all good it might have been set through a different * call. */ IndexOptions options = getDefaultIndexOption(); if (options == IndexOptions.NONE) { // can happen when an existing type on the same index has disabled indexing // since we inherit the default field type from the first mapper that is // created on an index throw new IllegalArgumentException("mapper [" + name + "] has different [index] values from other types" + " of the same index"); } fieldType.setIndexOptions(options); } } else { fieldType.setIndexOptions(IndexOptions.NONE); } return builder; }
@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); } }
protected Builder(String name, MappedFieldType fieldType, MappedFieldType defaultFieldType) { super(name); this.fieldType = fieldType.clone(); this.defaultFieldType = defaultFieldType.clone(); this.defaultOptions = fieldType.indexOptions(); // we have to store it the fieldType is mutable this.docValuesSet = fieldType.hasDocValues(); multiFieldsBuilder = new MultiFields.Builder(); }
@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); } } }
/** * Returns true if a {@link SortedDocsProducer} should be used to optimize the execution. */ protected boolean checkIfSortedDocsIsApplicable(IndexReader reader, MappedFieldType fieldType) { if (fieldType == null || missing != null || (missingBucket && afterValue == null) || fieldType.indexOptions() == IndexOptions.NONE || // inverse of the natural order reverseMul == -1) { return false; } if (reader.hasDeletions() && (reader.numDocs() == 0 || (double) reader.numDocs() / (double) reader.maxDoc() < 0.5)) { // do not use the index if it has more than 50% of deleted docs return false; } return true; } }
if (fieldType == null || fieldType.indexOptions() == IndexOptions.NONE) { return null;
@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()))); } }
public static Engine.Index prepareIndex(DocumentMapperForType docMapper, Version indexCreatedVersion, SourceToParse source, long seqNo, long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin, long autoGeneratedIdTimestamp, boolean isRetry, long ifSeqNo, long ifPrimaryTerm) { long startTime = System.nanoTime(); ParsedDocument doc = docMapper.getDocumentMapper().parse(source); if (docMapper.getMapping() != null) { doc.addDynamicMappingsUpdate(docMapper.getMapping()); } Term uid; if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_beta1)) { uid = new Term(IdFieldMapper.NAME, Uid.encodeId(doc.id())); } else if (docMapper.getDocumentMapper().idFieldMapper().fieldType().indexOptions() != IndexOptions.NONE) { uid = new Term(IdFieldMapper.NAME, doc.id()); } else { uid = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(doc.type(), doc.id())); } return new Engine.Index(uid, doc, seqNo, primaryTerm, version, versionType, origin, startTime, autoGeneratedIdTimestamp, isRetry, ifSeqNo, ifPrimaryTerm); }
@Override public AllFieldMapper build(BuilderContext context) { // In case the mapping overrides these // TODO: this should be an exception! it doesnt make sense to not index this field if (fieldType.indexOptions() == IndexOptions.NONE) { fieldType.setIndexOptions(Defaults.FIELD_TYPE.indexOptions()); } else { fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(), Defaults.POSITION_INCREMENT_GAP)); fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(), Defaults.POSITION_INCREMENT_GAP)); fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), Defaults.POSITION_INCREMENT_GAP)); } fieldType.setTokenized(true); return new AllFieldMapper(fieldType, enabled, context.indexSettings()); } }
throw new SearchContextException(context, "cannot collapse on field `" + field + "` without `doc_values`"); if (fieldType.indexOptions() == IndexOptions.NONE && (innerHits != null && !innerHits.isEmpty())) { throw new SearchContextException(context, "cannot expand `inner_hits` for collapse field `" + field + "`, " + "only indexed field can retrieve `inner_hits`");
protected void setupFieldType(BuilderContext context) { fieldType.setName(buildFullName(context)); if (context.indexCreatedVersion().before(Version.V_5_0_0_alpha1)) { fieldType.setOmitNorms(fieldType.omitNorms() && fieldType.boost() == 1.0f); } if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) { fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER); } boolean defaultDocValues = defaultDocValues(context.indexCreatedVersion()); defaultFieldType.setHasDocValues(defaultDocValues); if (docValuesSet == false) { fieldType.setHasDocValues(defaultDocValues); } } }