Exemplo n.º 1
0
  private void removeObjectAndFieldMappers(DocumentMapper docMapper) {
    // we need to remove those mappers
    MapBuilder<String, FieldMappers> nameFieldMappers = newMapBuilder(this.nameFieldMappers);
    MapBuilder<String, FieldMappers> indexNameFieldMappers =
        newMapBuilder(this.indexNameFieldMappers);
    MapBuilder<String, FieldMappers> fullNameFieldMappers =
        newMapBuilder(this.fullNameFieldMappers);

    for (FieldMapper mapper : docMapper.mappers()) {
      FieldMappers mappers = nameFieldMappers.get(mapper.names().name());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          nameFieldMappers.remove(mapper.names().name());
        } else {
          nameFieldMappers.put(mapper.names().name(), mappers);
        }
      }

      mappers = indexNameFieldMappers.get(mapper.names().indexName());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          indexNameFieldMappers.remove(mapper.names().indexName());
        } else {
          indexNameFieldMappers.put(mapper.names().indexName(), mappers);
        }
      }

      mappers = fullNameFieldMappers.get(mapper.names().fullName());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          fullNameFieldMappers.remove(mapper.names().fullName());
        } else {
          fullNameFieldMappers.put(mapper.names().fullName(), mappers);
        }
      }
    }
    this.nameFieldMappers = nameFieldMappers.map();
    this.indexNameFieldMappers = indexNameFieldMappers.map();
    this.fullNameFieldMappers = fullNameFieldMappers.map();

    MapBuilder<String, ObjectMappers> fullPathObjectMappers =
        newMapBuilder(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.map();
  }
Exemplo n.º 2
0
    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());
    }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 5
0
 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();
 }
  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();
  }
Exemplo n.º 7
0
  private void addFieldMappers(FieldMapper[] fieldMappers) {
    synchronized (mutex) {
      MapBuilder<String, FieldMappers> nameFieldMappers = newMapBuilder(this.nameFieldMappers);
      MapBuilder<String, FieldMappers> indexNameFieldMappers =
          newMapBuilder(this.indexNameFieldMappers);
      MapBuilder<String, FieldMappers> fullNameFieldMappers =
          newMapBuilder(this.fullNameFieldMappers);
      for (FieldMapper fieldMapper : fieldMappers) {
        FieldMappers mappers = nameFieldMappers.get(fieldMapper.names().name());
        if (mappers == null) {
          mappers = new FieldMappers(fieldMapper);
        } else {
          mappers = mappers.concat(fieldMapper);
        }
        nameFieldMappers.put(fieldMapper.names().name(), mappers);

        mappers = indexNameFieldMappers.get(fieldMapper.names().indexName());
        if (mappers == null) {
          mappers = new FieldMappers(fieldMapper);
        } else {
          mappers = mappers.concat(fieldMapper);
        }
        indexNameFieldMappers.put(fieldMapper.names().indexName(), mappers);

        mappers = fullNameFieldMappers.get(fieldMapper.names().fullName());
        if (mappers == null) {
          mappers = new FieldMappers(fieldMapper);
        } else {
          mappers = mappers.concat(fieldMapper);
        }
        fullNameFieldMappers.put(fieldMapper.names().fullName(), mappers);
      }

      this.nameFieldMappers = nameFieldMappers.map();
      this.indexNameFieldMappers = indexNameFieldMappers.map();
      this.fullNameFieldMappers = fullNameFieldMappers.map();
    }
  }
Exemplo n.º 8
0
 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);
   }
 }
 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();
     }
   }
 }
Exemplo n.º 10
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()]);
   }
 }
Exemplo n.º 11
0
 private void addObjectMappers(ObjectMapper[] objectMappers) {
   synchronized (mutex) {
     MapBuilder<String, ObjectMappers> fullPathObjectMappers =
         newMapBuilder(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.map();
   }
 }
Exemplo n.º 12
0
  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);
  }
 @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();
 }
 private void addFieldMapper(
     String field,
     FieldMapper<?> fieldMapper,
     MapBuilder<String, FieldMappingMetaData> fieldMappings,
     boolean includeDefaults) {
   if (fieldMappings.containsKey(field)) {
     return;
   }
   try {
     XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
     builder.startObject();
     fieldMapper.toXContent(
         builder, includeDefaults ? includeDefaultsParams : ToXContent.EMPTY_PARAMS);
     builder.endObject();
     fieldMappings.put(
         field, new FieldMappingMetaData(fieldMapper.names().fullName(), builder.bytes()));
   } catch (IOException e) {
     throw new ElasticsearchException("failed to serialize XContent of field [" + field + "]", e);
   }
 }
 public Builder putMapping(String mappingType, String mappingSource) throws IOException {
   mappings.put(mappingType, new CompressedString(mappingSource));
   return this;
 }
Exemplo n.º 16
0
 private void addFacetParser(
     MapBuilder<String, FacetCollectorParser> builder, FacetCollectorParser facetCollectorParser) {
   for (String s : facetCollectorParser.names()) {
     builder.put(s, facetCollectorParser);
   }
 }
  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();
  }
Exemplo n.º 18
0
 public Builder putMapping(MappingMetaData mappingMd) {
   mappings.put(mappingMd.type(), mappingMd);
   return this;
 }
Exemplo n.º 19
0
 public Builder putAlias(AliasMetaData.Builder aliasMetaData) {
   aliases.put(aliasMetaData.alias(), aliasMetaData.build());
   return this;
 }