Search in sources :

Example 21 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project elasticsearch by elastic.

the class DynamicMappingIT method assertMappingsHaveField.

private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String type, String field) throws IOException {
    ImmutableOpenMap<String, MappingMetaData> indexMappings = mappings.getMappings().get("index");
    assertNotNull(indexMappings);
    MappingMetaData typeMappings = indexMappings.get(type);
    assertNotNull(typeMappings);
    Map<String, Object> typeMappingsMap = typeMappings.getSourceAsMap();
    Map<String, Object> properties = (Map<String, Object>) typeMappingsMap.get("properties");
    assertTrue("Could not find [" + field + "] in " + typeMappingsMap.toString(), properties.containsKey(field));
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) Map(java.util.Map)

Example 22 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project sonarqube by SonarSource.

the class IndexCreatorTest method create_index.

@Test
public void create_index() throws Exception {
    assertThat(mappings()).isEmpty();
    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] { new FakeIndexDefinition() }, new MapSettings());
    registry.start();
    IndexCreator creator = new IndexCreator(es.client(), registry);
    creator.start();
    // check that index is created with related mapping
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings();
    MappingMetaData mapping = mappings.get("fakes").get("fake");
    assertThat(mapping.type()).isEqualTo("fake");
    assertThat(mapping.getSourceAsMap()).isNotEmpty();
    assertThat(countMappingFields(mapping)).isEqualTo(2);
    assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date");
    assertThat(setting("fakes", "index.sonar_hash")).isNotEmpty();
    // of course do not delete indices on stop
    creator.stop();
    assertThat(mappings()).isNotEmpty();
}
Also used : MapSettings(org.sonar.api.config.MapSettings) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Test(org.junit.Test)

Example 23 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project elasticsearch-skywalker by jprante.

the class MetaDataToXContent method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field("version", metadata.version());
    builder.field("numberOfShards", metadata.numberOfShards());
    builder.startArray("concreteIndices");
    for (String index : metadata.concreteAllIndices()) {
        builder.value(index);
    }
    builder.endArray();
    ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> aliases = metadata.getAliases();
    builder.startArray("aliases");
    for (ObjectCursor<String> alias : aliases.keys()) {
        builder.startObject(alias.value);
        builder.startArray("aliasMetadata");
        for (ObjectCursor<String> s : aliases.get(alias.value).keys()) {
            builder.startObject();
            AliasMetaData amd = aliases.get(alias.value).get(s.value);
            builder.field("alias", amd.getAlias());
            builder.field("filter", amd.getFilter().string());
            builder.field("indexRouting", amd.getIndexRouting());
            builder.field("searchRouting", amd.getSearchRouting());
            builder.endObject();
        }
        builder.endArray();
        builder.endObject();
    }
    builder.endArray();
    builder.startArray("indexes");
    ImmutableOpenMap<String, IndexMetaData> indices = metadata.getIndices();
    for (ObjectCursor<String> s : indices.keys()) {
        IndexMetaData imd = indices.get(s.value);
        builder.startObject();
        builder.field("index", imd.getIndex());
        builder.field("state", imd.getState().name());
        builder.field("numberOfReplicas", imd.getNumberOfReplicas());
        builder.field("numberOfShards", imd.getNumberOfShards());
        builder.field("totalNumberOfShards", imd.getTotalNumberOfShards());
        builder.field("version", imd.getVersion());
        builder.field("settings", imd.getSettings().getAsMap());
        ImmutableOpenMap<String, MappingMetaData> m = imd.getMappings();
        // skip mappings here
        builder.endObject();
    }
    builder.endArray();
    builder.startArray("templates");
    ImmutableOpenMap<String, IndexTemplateMetaData> templates = metadata.getTemplates();
    for (ObjectCursor<String> s : templates.keys()) {
        IndexTemplateMetaData itmd = templates.get(s.value);
        itmd.getName();
        itmd.getOrder();
        itmd.getTemplate();
        itmd.getSettings();
        itmd.getMappings();
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 24 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project graylog2-server by Graylog2.

the class Indices method areReopened.

public Map<String, Boolean> areReopened(Collection<String> indices) {
    final ClusterStateResponse clusterState = c.admin().cluster().prepareState().all().get();
    final ImmutableOpenMap<String, IndexMetaData> indicesMetaData = clusterState.getState().getMetaData().getIndices();
    return indices.stream().collect(Collectors.toMap(index -> index, index -> checkForReopened(indicesMetaData.get(index))));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) SortBuilders(org.elasticsearch.search.sort.SortBuilders) DateTimeZone(org.joda.time.DateTimeZone) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) LoggerFactory(org.slf4j.LoggerFactory) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) IndexClosedException(org.elasticsearch.indices.IndexClosedException) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) WriteConsistencyLevel(org.elasticsearch.action.WriteConsistencyLevel) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) IndexSet(org.graylog2.indexer.IndexSet) IndexMapping(org.graylog2.indexer.IndexMapping) Max(org.elasticsearch.search.aggregations.metrics.max.Max) Collectors.toSet(java.util.stream.Collectors.toSet) SearchHit(org.elasticsearch.search.SearchHit) SearchType(org.elasticsearch.action.search.SearchType) ImmutableSet(com.google.common.collect.ImmutableSet) Min(org.elasticsearch.search.aggregations.metrics.min.Min) ImmutableMap(com.google.common.collect.ImmutableMap) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) Collection(java.util.Collection) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Set(java.util.Set) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) List(java.util.List) AuditActor(org.graylog2.audit.AuditActor) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) Optional(java.util.Optional) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) HashMap(java.util.HashMap) SearchRequest(org.elasticsearch.action.search.SearchRequest) Singleton(javax.inject.Singleton) ActionFuture(org.elasticsearch.action.ActionFuture) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) Inject(javax.inject.Inject) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) GetIndexRequestBuilder(org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder) ImmutableList(com.google.common.collect.ImmutableList) NodeId(org.graylog2.plugin.system.NodeId) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) TimeValue(org.elasticsearch.common.unit.TimeValue) ES_INDEX_CREATE(org.graylog2.audit.AuditEventTypes.ES_INDEX_CREATE) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) Duration(com.github.joschi.jadconfig.util.Duration) Messages(org.graylog2.indexer.messages.Messages) AuditEventSender(org.graylog2.audit.AuditEventSender) Nullable(javax.annotation.Nullable) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) Logger(org.slf4j.Logger) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) Client(org.elasticsearch.client.Client) DateTime(org.joda.time.DateTime) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) TimeUnit(java.util.concurrent.TimeUnit) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SortParseElement(org.elasticsearch.search.sort.SortParseElement) UnmodifiableIterator(com.google.common.collect.UnmodifiableIterator) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) Collections(java.util.Collections) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 25 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project crate by crate.

the class DefaultTemplateService method createCopyWithDefaultTemplateAdded.

private static ImmutableOpenMap<String, IndexTemplateMetaData> createCopyWithDefaultTemplateAdded(ImmutableOpenMap<String, IndexTemplateMetaData> currentTemplates) throws IOException {
    IndexTemplateMetaData defaultTemplate = IndexTemplateMetaData.builder(TEMPLATE_NAME).order(0).putMapping(Constants.DEFAULT_MAPPING_TYPE, DEFAULT_MAPPING_SOURCE).template("*").build();
    ImmutableOpenMap.Builder<String, IndexTemplateMetaData> builder = ImmutableOpenMap.builder(currentTemplates);
    builder.put(TEMPLATE_NAME, defaultTemplate);
    return builder.build();
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Aggregations

ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)38 Settings (org.elasticsearch.common.settings.Settings)16 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)15 ClusterState (org.elasticsearch.cluster.ClusterState)14 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)13 MetaData (org.elasticsearch.cluster.metadata.MetaData)10 IOException (java.io.IOException)9 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)9 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)9 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)8 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)8 ShardId (org.elasticsearch.index.shard.ShardId)8 Map (java.util.Map)7 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)7 ClusterInfoService (org.elasticsearch.cluster.ClusterInfoService)7 DiskUsage (org.elasticsearch.cluster.DiskUsage)7 DevNullClusterInfo (org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo)7 DiskThresholdSettings (org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)7 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)7