Search in sources :

Example 11 with Settings

use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.

the class IndicesClientIT method testClone.

@SuppressWarnings("unchecked")
public void testClone() throws IOException {
    createIndex("source", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
    updateIndexSettings("source", Settings.builder().put("index.blocks.write", true));
    ResizeRequest resizeRequest = new ResizeRequest("target", "source");
    resizeRequest.setResizeType(ResizeType.CLONE);
    Settings targetSettings = Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build();
    resizeRequest.setTargetIndex(new org.opensearch.action.admin.indices.create.CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
    ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::clone, highLevelClient().indices()::cloneAsync);
    assertTrue(resizeResponse.isAcknowledged());
    assertTrue(resizeResponse.isShardsAcknowledged());
    Map<String, Object> getIndexResponse = getAsMap("target");
    Map<String, Object> indexSettings = (Map<String, Object>) XContentMapValues.extractValue("target.settings.index", getIndexResponse);
    assertNotNull(indexSettings);
    assertEquals("2", indexSettings.get("number_of_shards"));
    assertEquals("0", indexSettings.get("number_of_replicas"));
    Map<String, Object> aliasData = (Map<String, Object>) XContentMapValues.extractValue("target.aliases.alias", getIndexResponse);
    assertNotNull(aliasData);
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) Alias(org.opensearch.action.admin.indices.alias.Alias) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashMap(java.util.HashMap) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 12 with Settings

use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.

the class IndicesClientDocumentationIT method testSimulateIndexTemplate.

public void testSimulateIndexTemplate() throws Exception {
    RestHighLevelClient client = highLevelClient();
    {
        // <1>
        PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template");
        Template template = new Template(Settings.builder().put("index.number_of_replicas", 3).build(), null, null);
        ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("pattern-1", "log-*"), template, null, null, null, null);
        request.indexTemplate(composableIndexTemplate);
        assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
    }
    // tag::simulate-index-template-request
    // <1>
    SimulateIndexTemplateRequest simulateRequest = new SimulateIndexTemplateRequest("log-000001");
    PutComposableIndexTemplateRequest newIndexTemplateRequest = new PutComposableIndexTemplateRequest().name("used-for-simulation");
    Settings settings = Settings.builder().put("index.number_of_shards", 6).build();
    // <2>
    Template template = new Template(settings, null, null);
    ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("log-*"), template, null, 90L, null, null);
    newIndexTemplateRequest.indexTemplate(composableIndexTemplate);
    // <2>
    simulateRequest.indexTemplateV2Request(newIndexTemplateRequest);
    // end::simulate-index-template-request
    // tag::simulate-index-template-response
    SimulateIndexTemplateResponse simulateIndexTemplateResponse = client.indices().simulateIndexTemplate(simulateRequest, RequestOptions.DEFAULT);
    // <1>
    assertThat(simulateIndexTemplateResponse.resolvedTemplate().settings().get("index.number_of_shards"), is("6"));
    assertThat(simulateIndexTemplateResponse.overlappingTemplates().get("my-template"), // <2>
    containsInAnyOrder("pattern-1", "log-*"));
    // end::simulate-index-template-response
    // tag::simulate-index-template-execute-listener
    ActionListener<SimulateIndexTemplateResponse> listener = new ActionListener<SimulateIndexTemplateResponse>() {

        @Override
        public void onResponse(SimulateIndexTemplateResponse response) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::simulate-index-template-execute-listener
    final CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::simulate-index-template-execute-async
    // <1>
    client.indices().simulateIndexTemplateAsync(simulateRequest, RequestOptions.DEFAULT, listener);
    // end::simulate-index-template-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) SimulateIndexTemplateResponse(org.opensearch.client.indices.SimulateIndexTemplateResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException) ComponentTemplate(org.opensearch.cluster.metadata.ComponentTemplate) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Template(org.opensearch.cluster.metadata.Template)

Example 13 with Settings

use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.

the class IndicesClientDocumentationIT method testIndexPutSettings.

@SuppressWarnings("unused")
public void testIndexPutSettings() throws Exception {
    RestHighLevelClient client = highLevelClient();
    {
        CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
        assertTrue(createIndexResponse.isAcknowledged());
    }
    // tag::indices-put-settings-request
    // <1>
    UpdateSettingsRequest request = new UpdateSettingsRequest("index1");
    UpdateSettingsRequest requestMultiple = // <2>
    new UpdateSettingsRequest("index1", "index2");
    // <3>
    UpdateSettingsRequest requestAll = new UpdateSettingsRequest();
    // end::indices-put-settings-request
    // tag::indices-put-settings-create-settings
    String settingKey = "index.number_of_replicas";
    int settingValue = 0;
    Settings settings = Settings.builder().put(settingKey, settingValue).build();
    // end::indices-put-settings-create-settings
    // tag::indices-put-settings-request-index-settings
    request.settings(settings);
    // end::indices-put-settings-request-index-settings
    {
        // tag::indices-put-settings-settings-builder
        Settings.Builder settingsBuilder = Settings.builder().put(settingKey, settingValue);
        // <1>
        request.settings(settingsBuilder);
    // end::indices-put-settings-settings-builder
    }
    {
        // tag::indices-put-settings-settings-map
        Map<String, Object> map = new HashMap<>();
        map.put(settingKey, settingValue);
        // <1>
        request.settings(map);
    // end::indices-put-settings-settings-map
    }
    {
        // tag::indices-put-settings-settings-source
        request.settings("{\"index.number_of_replicas\": \"2\"}", // <1>
        XContentType.JSON);
    // end::indices-put-settings-settings-source
    }
    // tag::indices-put-settings-request-preserveExisting
    // <1>
    request.setPreserveExisting(false);
    // end::indices-put-settings-request-preserveExisting
    // tag::indices-put-settings-request-timeout
    // <1>
    request.timeout(TimeValue.timeValueMinutes(2));
    // <2>
    request.timeout("2m");
    // end::indices-put-settings-request-timeout
    // tag::indices-put-settings-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::indices-put-settings-request-masterTimeout
    // tag::indices-put-settings-request-indicesOptions
    // <1>
    request.indicesOptions(IndicesOptions.lenientExpandOpen());
    // end::indices-put-settings-request-indicesOptions
    // tag::indices-put-settings-execute
    AcknowledgedResponse updateSettingsResponse = client.indices().putSettings(request, RequestOptions.DEFAULT);
    // end::indices-put-settings-execute
    // tag::indices-put-settings-response
    // <1>
    boolean acknowledged = updateSettingsResponse.isAcknowledged();
    // end::indices-put-settings-response
    assertTrue(acknowledged);
    // tag::indices-put-settings-execute-listener
    ActionListener<AcknowledgedResponse> listener = new ActionListener<AcknowledgedResponse>() {

        @Override
        public void onResponse(AcknowledgedResponse updateSettingsResponse) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::indices-put-settings-execute-listener
    // Replace the empty listener by a blocking listener in test
    final CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::indices-put-settings-execute-async
    // <1>
    client.indices().putSettingsAsync(request, RequestOptions.DEFAULT, listener);
    // end::indices-put-settings-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) QueryBuilder(org.opensearch.index.query.QueryBuilder) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) Map(java.util.Map) HashMap(java.util.HashMap) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 14 with Settings

use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.

the class UpdateByQueryIT method testUpdateByQueryConflict.

public void testUpdateByQueryConflict() throws IOException {
    final String index = "testupdatebyqueryconflict";
    final Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
    createIndex(index, settings);
    final BulkRequest bulkRequest = new BulkRequest().add(new IndexRequest(index).id("1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).add(new IndexRequest(index).id("2").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
    assertThat(highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT).status(), equalTo(RestStatus.OK));
    putConflictPipeline();
    final UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
    updateByQueryRequest.indices(index);
    updateByQueryRequest.setRefresh(true);
    updateByQueryRequest.setPipeline(CONFLICT_PIPELINE_ID);
    final BulkByScrollResponse response = highLevelClient().updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT);
    assertThat(response.getVersionConflicts(), equalTo(1L));
    assertThat(response.getSearchFailures(), empty());
    assertThat(response.getBulkFailures(), hasSize(1));
    assertThat(response.getBulkFailures().stream().map(BulkItemResponse.Failure::getMessage).collect(Collectors.toSet()), everyItem(containsString("version conflict")));
    assertThat(response.getTotal(), equalTo(2L));
    assertThat(response.getCreated(), equalTo(0L));
    assertThat(response.getUpdated(), equalTo(1L));
    assertThat(response.getDeleted(), equalTo(0L));
    assertThat(response.getNoops(), equalTo(0L));
    assertThat(response.getBatches(), equalTo(1));
    assertTrue(response.getTook().getMillis() > 0);
}
Also used : BulkRequest(org.opensearch.action.bulk.BulkRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexRequest(org.opensearch.action.index.IndexRequest) Settings(org.opensearch.common.settings.Settings) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) BulkByScrollResponse(org.opensearch.index.reindex.BulkByScrollResponse)

Example 15 with Settings

use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.

the class GetIndexResponseTests method createServerTestInstance.

@Override
protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerTestInstance(XContentType xContentType) {
    String[] indices = generateRandomStringArray(5, 5, false, false);
    ImmutableOpenMap.Builder<String, MappingMetadata> mappings = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<String, List<AliasMetadata>> aliases = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<String, String> dataStreams = ImmutableOpenMap.builder();
    IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS;
    boolean includeDefaults = randomBoolean();
    for (String index : indices) {
        mappings.put(index, createMappingsForIndex());
        List<AliasMetadata> aliasMetadataList = new ArrayList<>();
        int aliasesNum = randomIntBetween(0, 3);
        for (int i = 0; i < aliasesNum; i++) {
            aliasMetadataList.add(GetAliasesResponseTests.createAliasMetadata());
        }
        CollectionUtil.timSort(aliasMetadataList, Comparator.comparing(AliasMetadata::alias));
        aliases.put(index, Collections.unmodifiableList(aliasMetadataList));
        Settings.Builder builder = Settings.builder();
        builder.put(RandomCreateIndexGenerator.randomIndexSettings());
        settings.put(index, builder.build());
        if (includeDefaults) {
            defaultSettings.put(index, indexScopedSettings.diff(settings.get(index), Settings.EMPTY));
        }
        if (randomBoolean()) {
            dataStreams.put(index, randomAlphaOfLength(5).toLowerCase(Locale.ROOT));
        }
    }
    return new org.opensearch.action.admin.indices.get.GetIndexResponse(indices, mappings.build(), aliases.build(), settings.build(), defaultSettings.build(), dataStreams.build());
}
Also used : AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ArrayList(java.util.ArrayList) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) ArrayList(java.util.ArrayList) List(java.util.List) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings)

Aggregations

Settings (org.opensearch.common.settings.Settings)1293 IndexSettings (org.opensearch.index.IndexSettings)304 Matchers.containsString (org.hamcrest.Matchers.containsString)221 ClusterSettings (org.opensearch.common.settings.ClusterSettings)196 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)158 ClusterState (org.opensearch.cluster.ClusterState)150 IOException (java.io.IOException)127 ArrayList (java.util.ArrayList)127 Version (org.opensearch.Version)122 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)121 List (java.util.List)108 Index (org.opensearch.index.Index)106 Path (java.nio.file.Path)104 Map (java.util.Map)97 HashMap (java.util.HashMap)95 HashSet (java.util.HashSet)86 ShardId (org.opensearch.index.shard.ShardId)86 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)83 Environment (org.opensearch.env.Environment)82 ShardRouting (org.opensearch.cluster.routing.ShardRouting)71