public Builder put(IndexMetaData.Builder indexMetaDataBuilder) { // we know its a new one, increment the version and store indexMetaDataBuilder.version(indexMetaDataBuilder.version() + 1); IndexMetaData indexMetaData = indexMetaDataBuilder.build(); indices.put(indexMetaData.getIndex().getName(), indexMetaData); return this; }
/* * Finds all mappings for types and concrete indices. Types are expanded to * include all types that match the glob patterns in the types array. Empty * types array, null or {"_all"} will be expanded to all types available for * the given indices. */ public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> findMappings( String[] concreteIndices, final String[] types) { assert types != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return ImmutableOpenMap.of(); } ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder(); Iterable<String> intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index); ImmutableOpenMap.Builder<String, MappingMetaData> filteredMappings; if (isAllTypes(types)) { indexMapBuilder.put( index, indexMetaData.getMappings()); // No types specified means get it all } else { filteredMappings = ImmutableOpenMap.builder(); for (ObjectObjectCursor<String, MappingMetaData> cursor : indexMetaData.getMappings()) { if (Regex.simpleMatch(types, cursor.key)) { filteredMappings.put(cursor.key, cursor.value); } } if (!filteredMappings.isEmpty()) { indexMapBuilder.put(index, filteredMappings.build()); } } } return indexMapBuilder.build(); }
public Builder put(IndexMetaData indexMetaData, boolean incrementVersion) { if (indices.get(indexMetaData.getIndex().getName()) == indexMetaData) { return this; } // if we put a new index metadata, increment its version if (incrementVersion) { indexMetaData = IndexMetaData.builder(indexMetaData).version(indexMetaData.getVersion() + 1).build(); } indices.put(indexMetaData.getIndex().getName(), indexMetaData); return this; }
protected void addMappers( Collection<ObjectMapper> objectMappers, Collection<FieldMapper> fieldMappers) { assert mappingLock.isWriteLockedByCurrentThread(); ImmutableOpenMap.Builder<String, ObjectMapper> fullPathObjectMappers = ImmutableOpenMap.builder(this.fullPathObjectMappers); for (ObjectMapper objectMapper : objectMappers) { fullPathObjectMappers.put(objectMapper.fullPath(), objectMapper); if (objectMapper.nested().isNested()) { hasNested = true; } } this.fullPathObjectMappers = fullPathObjectMappers.build(); this.fieldTypes = this.fieldTypes.copyAndAddAll(fieldMappers); }
private MetaData buildMetaDataForVersion(MetaData metaData, long version) { ImmutableOpenMap.Builder<String, IndexMetaData> indices = ImmutableOpenMap.builder(metaData.indices()); indices.put( "test" + version, IndexMetaData.builder("test" + version) .settings( Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)) .numberOfShards((int) version) .numberOfReplicas(0) .build()); return MetaData.builder(metaData) .transientSettings(Settings.builder().put("test", version).build()) .indices(indices.build()) .build(); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder(); for (int j = 0; j < valueSize; j++) { typeMapBuilder.put(in.readString(), new MappingMetaData(in)); } indexMapBuilder.put(key, typeMapBuilder.build()); } mappings = indexMapBuilder.build(); }
StoreDirectory(Distributor distributor) throws IOException { this.distributor = distributor; synchronized (mutex) { ImmutableOpenMap.Builder<String, StoreFileMetaData> builder = ImmutableOpenMap.builder(); Map<String, String> checksums = readChecksums(distributor.all(), new HashMap<String, String>()); for (Directory delegate : distributor.all()) { for (String file : delegate.listAll()) { String checksum = checksums.get(file); builder.put( file, new StoreFileMetaData(file, delegate.fileLength(file), checksum, delegate)); } } filesMetadata = builder.build(); files = filesMetadata.keys().toArray(String.class); } }
private void addObjectMappers(ObjectMapper[] objectMappers) { synchronized (mappersMutex) { ImmutableOpenMap.Builder<String, ObjectMappers> fullPathObjectMappers = ImmutableOpenMap.builder(this.fullPathObjectMappers); for (ObjectMapper objectMapper : objectMappers) { ObjectMappers mappers = fullPathObjectMappers.get(objectMapper.fullPath()); if (mappers == null) { mappers = new ObjectMappers(objectMapper); } else { mappers = mappers.concat(objectMapper); } fullPathObjectMappers.put(objectMapper.fullPath(), mappers); // update the hasNested flag if (objectMapper.nested().isNested()) { hasNested = true; } } this.fullPathObjectMappers = fullPathObjectMappers.build(); } }
private void removeObjectAndFieldMappers(DocumentMapper docMapper) { synchronized (mappersMutex) { fieldMappers.removeMappers(docMapper.mappers()); ImmutableOpenMap.Builder<String, ObjectMappers> fullPathObjectMappers = ImmutableOpenMap.builder(this.fullPathObjectMappers); for (ObjectMapper mapper : docMapper.objectMappers().values()) { ObjectMappers mappers = fullPathObjectMappers.get(mapper.fullPath()); if (mappers != null) { mappers = mappers.remove(mapper); if (mappers.isEmpty()) { fullPathObjectMappers.remove(mapper.fullPath()); } else { fullPathObjectMappers.put(mapper.fullPath(), mappers); } } } this.fullPathObjectMappers = fullPathObjectMappers.build(); } }
public Builder putCustom(String type, Custom custom) { customs.put(type, custom); return this; }
public Builder put(IndexTemplateMetaData template) { templates.put(template.name(), template); return this; }
public Builder putAlias(AliasMetaData.Builder aliasMetaData) { aliases.put(aliasMetaData.alias(), aliasMetaData.build()); return this; }
public Builder putMapping(MappingMetaData mappingMd) { mappings.put(mappingMd.type(), mappingMd); return this; }