private static void checkIndexCompatibility(IndexSettings settings, String name) { if (!settings.isSingleType()) { throw new IllegalStateException("Cannot create a field alias [" + name + "] " + "for index [" + settings.getIndex().getName() + "]. Field aliases can only " + "be specified on indexes that enforce a single mapping type."); } } }
private Term extractUidForDelete(String type, String id) { if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { assert indexSettings.isSingleType(); // This is only correct because we create types dynamically on delete operations // otherwise this could match the same _id from a different type BytesRef idBytes = Uid.encodeId(id); return new Term(IdFieldMapper.NAME, idBytes); } else if (indexSettings.isSingleType()) { // This is only correct because we create types dynamically on delete operations // otherwise this could match the same _id from a different type return new Term(IdFieldMapper.NAME, id); } else { return new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(type, id)); } }
public void postProcess(MapperService mapperService) { if (mapperService.getIndexSettings().isSingleType()) { final Collection<String> types = mapperService.types(); assert types.size() <= 1 : types; if (types.isEmpty() == false) { type = types.iterator().next(); } } for (Map.Entry<String, List<Object>> entry : fields().entrySet()) { MappedFieldType fieldType = mapperService.fullName(entry.getKey()); if (fieldType == null) { throw new IllegalStateException("Field [" + entry.getKey() + "] exists in the index but not in mappings"); } List<Object> fieldValues = entry.getValue(); for (int i = 0; i < fieldValues.size(); i++) { fieldValues.set(i, fieldType.valueForDisplay(fieldValues.get(i))); } } }
/** Return a term that uniquely identifies the document, or {@code null} if the type is not allowed. */ public Term createUidTerm(String type, String id) { if (hasMapping(type) == false) { return null; } if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)) { assert indexSettings.isSingleType(); return new Term(IdFieldMapper.NAME, Uid.encodeId(id)); } else if (indexSettings.isSingleType()) { return new Term(IdFieldMapper.NAME, id); } else { return new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(type, id)); } } }
LeafFieldsLookup(MapperService mapperService, @Nullable String[] types, LeafReader reader) { this.mapperService = mapperService; this.singleType = mapperService.getIndexSettings().isSingleType(); this.types = types; this.reader = reader; this.fieldVisitor = new SingleFieldsVisitor(null); }
@Override public Query termsQuery(List<?> values, QueryShardContext context) { if (context.getIndexSettings().isSingleType()) { Collection<String> indexTypes = context.getMapperService().types(); if (indexTypes.isEmpty()) {
private static MappedFieldType defaultFieldType(IndexSettings indexSettings) { MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); if (indexSettings.isSingleType()) { defaultFieldType.setIndexOptions(IndexOptions.NONE); defaultFieldType.setHasDocValues(false); } else { defaultFieldType.setIndexOptions(IndexOptions.DOCS); defaultFieldType.setHasDocValues(true); } return defaultFieldType; }
static MappedFieldType defaultFieldType(IndexSettings indexSettings) { MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); if (indexSettings.isSingleType()) { defaultFieldType.setIndexOptions(IndexOptions.NONE); defaultFieldType.setStored(false); } else { defaultFieldType.setIndexOptions(IndexOptions.DOCS); defaultFieldType.setStored(true); } return defaultFieldType; }
static MappedFieldType defaultFieldType(IndexSettings indexSettings) { MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone(); if (indexSettings.isSingleType()) { defaultFieldType.setIndexOptions(IndexOptions.DOCS); defaultFieldType.setStored(true); } else { defaultFieldType.setIndexOptions(IndexOptions.NONE); defaultFieldType.setStored(false); } return defaultFieldType; }
if (indexSettings.isSingleType()) { Set<String> actualTypes = new HashSet<>(mappers.keySet()); documentMappers.forEach(mapper -> actualTypes.add(mapper.type()));
if (context.mapperService().getIndexSettings().isSingleType()) { IndexableField idField = parentDoc.getField(IdFieldMapper.NAME); if (idField != null) {
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) { if (context.getIndexSettings().isSingleType() == false) { return new TermRangeQuery(name(), lowerTerm == null ? null : indexedValueForSearch(lowerTerm), upperTerm == null ? null : indexedValueForSearch(upperTerm), includeLower, includeUpper);
private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, String type, String id, VersionType versionType, long ifSeqNo, long ifPrimaryTerm, Engine.Operation.Origin origin) throws IOException { assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm + "]"; assert versionType.validateVersionForWrites(version); ensureWriteAllowed(origin); if (indexSettings().isSingleType()) { // When there is a single type, the unique identifier is only composed of the _id, // so there is no way to differentiate foo#1 from bar#1. This is especially an issue // if a user first deletes foo#1 and then indexes bar#1: since we do not encode the // _type in the uid it might look like we are reindexing the same document, which // would fail if bar#1 is indexed with a lower version than foo#1 was deleted with. // In order to work around this issue, we make deletions create types. This way, we // fail if index and delete operations do not use the same type. try{ Mapping update = docMapper(type).getMapping(); if (update != null) { return new Engine.DeleteResult(update); } } catch (MapperParsingException | IllegalArgumentException | TypeMissingException e) { return new Engine.DeleteResult(e, version, operationPrimaryTerm, seqNo, false); } } final Term uid = extractUidForDelete(type, id); final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm); return delete(engine, delete); }
DEPRECATION_LOGGER.deprecated( "As of version 7.0 Elasticsearch will require that a [field] parameter is provided when a [seed] is set"); if (context.getIndexSettings().isSingleType()) { fieldType = context.getMapperService().fullName(IdFieldMapper.NAME); } else {
boolean useTermQuery = false; if (UidFieldMapper.NAME.equals(field)) { if (context.getIndexSettings().isSingleType()) { if (context.getIndexSettings().isSingleType() == false) {
/** Return a term that uniquely identifies the document, or {@code null} if the type is not allowed. */ public Term createUidTerm(String type, String id) { if (hasMapping(type) == false) { return null; } if (indexSettings.isSingleType()) { return new Term(IdFieldMapper.NAME, id); } else { return new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(type, id)); } } }
updateAutoIdTimestamp(Long.MAX_VALUE, true); this.uidField = engineConfig.getIndexSettings().isSingleType() ? IdFieldMapper.NAME : UidFieldMapper.NAME; final TranslogDeletionPolicy translogDeletionPolicy = new TranslogDeletionPolicy( engineConfig.getIndexSettings().getTranslogRetentionSize().getBytes(),
@Override protected Query doToQuery(QueryShardContext context) throws IOException { if (context.getIndexSettings().isSingleType()) { return joinFieldDoToQuery(context); } else { return parentFieldDoToQuery(context); } }
@Override protected void doBuild(SearchContext parentSearchContext, InnerHitsContext innerHitsContext) throws IOException { if (parentSearchContext.mapperService().getIndexSettings().isSingleType()) { handleJoinFieldInnerHits(parentSearchContext, innerHitsContext); } else { handleParentFieldInnerHits(parentSearchContext, innerHitsContext); } }
@Override protected ValuesSourceConfig<WithOrdinals> resolveConfig(SearchContext context) { ValuesSourceConfig<WithOrdinals> config = new ValuesSourceConfig<>(ValuesSourceType.BYTES); if (context.mapperService().getIndexSettings().isSingleType()) { joinFieldResolveConfig(context, config); } else { parentFieldResolveConfig(context, config); } return config; }