public IndexMetaData build() {
      MapBuilder<String, AliasMetaData> tmpAliases = aliases;
      Settings tmpSettings = settings;

      // For backward compatibility
      String[] legacyAliases = settings.getAsArray("index.aliases");
      if (legacyAliases.length > 0) {
        tmpAliases = MapBuilder.newMapBuilder();
        for (String alias : legacyAliases) {
          AliasMetaData aliasMd = AliasMetaData.newAliasMetaDataBuilder(alias).build();
          tmpAliases.put(alias, aliasMd);
        }
        tmpAliases.putAll(aliases.immutableMap());
        // Remove index.aliases from settings once they are migrated to the new data structure
        tmpSettings =
            ImmutableSettings.settingsBuilder().put(settings).putArray("index.aliases").build();
      }

      // update default mapping on the MappingMetaData
      if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
        MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING);
        for (MappingMetaData mappingMetaData : mappings.map().values()) {
          mappingMetaData.updateDefaultMapping(defaultMapping);
        }
      }

      return new IndexMetaData(
          index,
          version,
          state,
          tmpSettings,
          mappings.immutableMap(),
          tmpAliases.immutableMap(),
          customs.immutableMap());
    }
 /**
  * Constructs the AggregatorParsers out of all the given parsers
  *
  * @param parsers The available aggregator parsers (dynamically injected by the {@link
  *     org.elasticsearch.search.aggregations.AggregationModule}).
  */
 @Inject
 public AggregatorParsers(Set<Aggregator.Parser> parsers) {
   MapBuilder<String, Aggregator.Parser> builder = MapBuilder.newMapBuilder();
   for (Aggregator.Parser parser : parsers) {
     builder.put(parser.type(), parser);
   }
   this.parsers = builder.immutableMap();
 }
 public FacetsParseElement() {
   MapBuilder<String, FacetCollectorParser> builder = newMapBuilder();
   addFacetParser(builder, new TermsFacetCollectorParser());
   addFacetParser(builder, new QueryFacetCollectorParser());
   addFacetParser(builder, new StatisticalFacetCollectorParser());
   addFacetParser(builder, new HistogramFacetCollectorParser());
   addFacetParser(builder, new GeoDistanceFacetCollectorParser());
   addFacetParser(builder, new RangeFacetCollectorParser());
   addFacetParser(builder, new FilterFacetCollectorParser());
   this.facetCollectorParsers = builder.immutableMap();
 }
Beispiel #4
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   MapBuilder<String, String> builder = MapBuilder.newMapBuilder();
   for (int i = in.readVInt(); i > 0; i--) {
     builder.put(in.readString(), in.readString());
   }
   userData = builder.immutableMap();
   generation = in.readLong();
   id = in.readOptionalString();
   numDocs = in.readInt();
 }
  private Map<String, FieldMappingMetaData> findFieldMappingsByType(
      DocumentMapper documentMapper, GetFieldMappingsIndexRequest request) {
    MapBuilder<String, FieldMappingMetaData> fieldMappings = new MapBuilder<>();
    final DocumentFieldMappers allFieldMappers = documentMapper.mappers();
    for (String field : request.fields()) {
      if (Regex.isMatchAllPattern(field)) {
        for (FieldMapper fieldMapper : allFieldMappers) {
          addFieldMapper(
              fieldMapper.fieldType().name(),
              fieldMapper,
              fieldMappings,
              request.includeDefaults());
        }
      } else if (Regex.isSimpleMatchPattern(field)) {
        // go through the field mappers 3 times, to make sure we give preference to the resolve
        // order: full name, index name, name.
        // also make sure we only store each mapper once.
        Collection<FieldMapper> remainingFieldMappers = newLinkedList(allFieldMappers);
        for (Iterator<FieldMapper> it = remainingFieldMappers.iterator(); it.hasNext(); ) {
          final FieldMapper fieldMapper = it.next();
          if (Regex.simpleMatch(field, fieldMapper.fieldType().name())) {
            addFieldMapper(
                fieldMapper.fieldType().name(),
                fieldMapper,
                fieldMappings,
                request.includeDefaults());
            it.remove();
          }
        }
        for (Iterator<FieldMapper> it = remainingFieldMappers.iterator(); it.hasNext(); ) {
          final FieldMapper fieldMapper = it.next();
          if (Regex.simpleMatch(field, fieldMapper.fieldType().name())) {
            addFieldMapper(
                fieldMapper.fieldType().name(),
                fieldMapper,
                fieldMappings,
                request.includeDefaults());
            it.remove();
          }
        }

      } else {
        // not a pattern
        FieldMapper fieldMapper = allFieldMappers.smartNameFieldMapper(field);
        if (fieldMapper != null) {
          addFieldMapper(field, fieldMapper, fieldMappings, request.includeDefaults());
        } else if (request.probablySingleFieldRequest()) {
          fieldMappings.put(field, FieldMappingMetaData.NULL);
        }
      }
    }
    return fieldMappings.immutableMap();
  }
 public void clear() {
   totalStats.clear();
   synchronized (this) {
     if (!groupsStats.isEmpty()) {
       MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder();
       for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) {
         if (typeStats.getValue().totalCurrent() > 0) {
           typeStats.getValue().clear();
           typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue());
         }
       }
       groupsStats = typesStatsBuilder.immutableMap();
     }
   }
 }
 private void addObjectMappers(ObjectMapper... objectMappers) {
   synchronized (mutex) {
     MapBuilder<String, ObjectMapper> builder = MapBuilder.newMapBuilder(this.objectMappers);
     for (ObjectMapper objectMapper : objectMappers) {
       builder.put(objectMapper.fullPath(), objectMapper);
       if (objectMapper.nested().isNested()) {
         hasNestedObjects = true;
       }
     }
     this.objectMappers = builder.immutableMap();
   }
   for (ObjectMapperListener objectMapperListener : objectMapperListeners) {
     objectMapperListener.objectMappers(objectMappers);
   }
 }
Beispiel #8
0
 StoreDirectory(Distributor distributor) throws IOException {
   this.distributor = distributor;
   synchronized (mutex) {
     MapBuilder<String, StoreFileMetaData> builder = MapBuilder.newMapBuilder();
     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.immutableMap();
     files = filesMetadata.keySet().toArray(new String[filesMetadata.size()]);
   }
 }
  private void addMappers(
      Collection<ObjectMapper> objectMappers, Collection<FieldMapper> fieldMappers) {
    assert mappingLock.isWriteLockedByCurrentThread();
    // first ensure we don't have any incompatible new fields
    mapperService.checkNewMappersCompatibility(objectMappers, fieldMappers, true);

    // update mappers for this document type
    MapBuilder<String, ObjectMapper> builder = MapBuilder.newMapBuilder(this.objectMappers);
    for (ObjectMapper objectMapper : objectMappers) {
      builder.put(objectMapper.fullPath(), objectMapper);
      if (objectMapper.nested().isNested()) {
        hasNestedObjects = true;
      }
    }
    this.objectMappers = builder.immutableMap();
    this.fieldMappers = this.fieldMappers.copyAndAllAll(fieldMappers);

    // finally update for the entire index
    mapperService.addMappers(objectMappers, fieldMappers);
  }
 static {
   MapBuilder<String, PreBuiltDocValuesFormatProvider.Factory> builtInDocValuesFormatsX =
       MapBuilder.newMapBuilder();
   for (String name : DocValuesFormat.availableDocValuesFormats()) {
     builtInDocValuesFormatsX.put(
         name, new PreBuiltDocValuesFormatProvider.Factory(DocValuesFormat.forName(name)));
   }
   // LUCENE UPGRADE: update those DVF if necessary
   builtInDocValuesFormatsX.put(
       "default",
       new PreBuiltDocValuesFormatProvider.Factory(
           "default", DocValuesFormat.forName("Lucene45")));
   builtInDocValuesFormatsX.put(
       "memory",
       new PreBuiltDocValuesFormatProvider.Factory("memory", DocValuesFormat.forName("Memory")));
   builtInDocValuesFormatsX.put(
       "disk",
       new PreBuiltDocValuesFormatProvider.Factory("disk", DocValuesFormat.forName("Disk")));
   builtInDocValuesFormats = builtInDocValuesFormatsX.immutableMap();
 }
 @Inject
 public InternalTransportClusterAdminClient(
     Settings settings,
     TransportClientNodesService nodesService,
     ThreadPool threadPool,
     TransportService transportService,
     Map<String, GenericAction> actions) {
   this.nodesService = nodesService;
   this.threadPool = threadPool;
   MapBuilder<ClusterAction, TransportActionNodeProxy> actionsBuilder =
       new MapBuilder<ClusterAction, TransportActionNodeProxy>();
   for (GenericAction action : actions.values()) {
     if (action instanceof ClusterAction) {
       actionsBuilder.put(
           (ClusterAction) action,
           new TransportActionNodeProxy(settings, action, transportService));
     }
   }
   this.actions = actionsBuilder.immutableMap();
 }
 public IndexTemplateMetaData build() {
   return new IndexTemplateMetaData(name, order, template, settings, mappings.immutableMap());
 }
  private ImmutableMap<String, FieldMappingMetaData> findFieldMappingsByType(
      DocumentMapper documentMapper, GetFieldMappingsIndexRequest request)
      throws ElasticsearchException {
    MapBuilder<String, FieldMappingMetaData> fieldMappings = new MapBuilder<>();
    final List<FieldMapper> allFieldMappers = documentMapper.mappers().mappers();
    for (String field : request.fields()) {
      if (Regex.isMatchAllPattern(field)) {
        for (FieldMapper fieldMapper : allFieldMappers) {
          addFieldMapper(
              fieldMapper.names().fullName(),
              fieldMapper,
              fieldMappings,
              request.includeDefaults());
        }
      } else if (Regex.isSimpleMatchPattern(field)) {
        // go through the field mappers 3 times, to make sure we give preference to the resolve
        // order: full name, index name, name.
        // also make sure we only store each mapper once.
        boolean[] resolved = new boolean[allFieldMappers.size()];
        for (int i = 0; i < allFieldMappers.size(); i++) {
          FieldMapper fieldMapper = allFieldMappers.get(i);
          if (Regex.simpleMatch(field, fieldMapper.names().fullName())) {
            addFieldMapper(
                fieldMapper.names().fullName(),
                fieldMapper,
                fieldMappings,
                request.includeDefaults());
            resolved[i] = true;
          }
        }
        for (int i = 0; i < allFieldMappers.size(); i++) {
          if (resolved[i]) {
            continue;
          }
          FieldMapper fieldMapper = allFieldMappers.get(i);
          if (Regex.simpleMatch(field, fieldMapper.names().indexName())) {
            addFieldMapper(
                fieldMapper.names().indexName(),
                fieldMapper,
                fieldMappings,
                request.includeDefaults());
            resolved[i] = true;
          }
        }
        for (int i = 0; i < allFieldMappers.size(); i++) {
          if (resolved[i]) {
            continue;
          }
          FieldMapper fieldMapper = allFieldMappers.get(i);
          if (Regex.simpleMatch(field, fieldMapper.names().name())) {
            addFieldMapper(
                fieldMapper.names().name(), fieldMapper, fieldMappings, request.includeDefaults());
            resolved[i] = true;
          }
        }

      } else {
        // not a pattern
        FieldMapper fieldMapper = documentMapper.mappers().smartNameFieldMapper(field);
        if (fieldMapper != null) {
          addFieldMapper(field, fieldMapper, fieldMappings, request.includeDefaults());
        } else if (request.probablySingleFieldRequest()) {
          fieldMappings.put(field, FieldMappingMetaData.NULL);
        }
      }
    }
    return fieldMappings.immutableMap();
  }