Search in sources :

Example 1 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class OpenSearchRestHighLevelClientTestCase method initHighLevelClient.

@Before
public void initHighLevelClient() throws IOException {
    super.initClient();
    if (restHighLevelClient == null) {
        // Create the low-level client
        restClient = client();
        // Create the transport that provides JSON and http services to API clients
        OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
        // Create API client
        restHighLevelClient = new OpenSearchClient(transport);
    }
}
Also used : RestClientTransport(org.opensearch.client.transport.rest_client.RestClientTransport) JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) Before(org.junit.Before)

Example 2 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterGetSettings.

public void testClusterGetSettings() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    final String transientSettingValue = "10b";
    final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Map<String, JsonData> transientSettingsMap = new HashMap<>();
    Map<String, JsonData> persistentSettingsMap = new HashMap<>();
    transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
    persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
    PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
    openSearchClient.cluster().putSettings(request);
    GetClusterSettingsResponse getSettingsResponse = openSearchClient.cluster().getSettings(new GetClusterSettingsRequest.Builder().build());
    assertEquals(1, getSettingsResponse.persistent().size());
    assertEquals(1, getSettingsResponse.transient_().size());
    assertEquals(0, getSettingsResponse.defaults().size());
}
Also used : GetClusterSettingsResponse(org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse) HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) JsonData(org.opensearch.client.json.JsonData)

Example 3 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ApiConventionsTest method builderLambdas.

@Test(expected = TransportException.class)
public void builderLambdas() throws Exception {
    OpenSearchClient client = new OpenSearchClient(transport);
    // tag::builder-lambdas
    CreateIndexResponse createResponse = client.indices().create(createIndexBuilder -> createIndexBuilder.index("my-index").aliases("foo", aliasBuilder -> aliasBuilder.isWriteIndex(true)));
// end::builder-lambdas
}
Also used : OpenSearchAsyncClient(org.opensearch.client.opensearch.OpenSearchAsyncClient) Arrays(java.util.Arrays) Aggregation(org.opensearch.client.opensearch._types.aggregations.Aggregation) Alias(org.opensearch.client.opensearch.indices.Alias) Query(org.opensearch.client.opensearch._types.query_dsl.Query) CreateIndexRequest(org.opensearch.client.opensearch.indices.CreateIndexRequest) LogManager(java.util.logging.LogManager) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Test(org.junit.Test) HashMap(java.util.HashMap) CreateIndexResponse(org.opensearch.client.opensearch.indices.CreateIndexResponse) Logger(java.util.logging.Logger) SearchResponse(org.opensearch.client.opensearch.core.SearchResponse) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) TransportException(org.opensearch.client.transport.TransportException) List(java.util.List) SearchRequest(org.opensearch.client.opensearch.core.SearchRequest) NodeStatistics(org.opensearch.client.opensearch._types.NodeStatistics) SortOrder(org.opensearch.client.opensearch._types.SortOrder) ApiTypeHelper(org.opensearch.client.util.ApiTypeHelper) Map(java.util.Map) Assert(org.junit.Assert) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) CreateIndexResponse(org.opensearch.client.opensearch.indices.CreateIndexResponse) Test(org.junit.Test)

Example 4 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowClusterLevel.

public void testClusterHealthYellowClusterLevel() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    createIndex("index2", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().timeout(t -> t.time("5s")).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertEquals(response.indices().size(), 0);
}
Also used : GetClusterSettingsRequest(org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse) Collections.emptyMap(java.util.Collections.emptyMap) ShardHealthStats(org.opensearch.client.opensearch.cluster.health.ShardHealthStats) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) JsonData(org.opensearch.client.json.JsonData) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) EnableAllocationDecider(org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider) OpenSearchException(org.opensearch.client.opensearch._types.OpenSearchException) HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) HashMap(java.util.HashMap) GetClusterSettingsResponse(org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse) ResponseException(org.opensearch.client.ResponseException) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) HealthStatus(org.opensearch.client.opensearch._types.HealthStatus) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Level(org.opensearch.client.opensearch._types.Level) PutClusterSettingsResponse(org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse) HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Example 5 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowIndicesLevel.

public void testClusterHealthYellowIndicesLevel() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    String firstIndex = "index";
    String secondIndex = "index2";
    // including another index that we do not assert on, to ensure that we are not
    // accidentally asserting on entire cluster state
    String ignoredIndex = "tasks";
    createIndex(firstIndex, Settings.EMPTY);
    createIndex(secondIndex, Settings.EMPTY);
    if (randomBoolean()) {
        createIndex(ignoredIndex, Settings.EMPTY);
    }
    HealthRequest request = new HealthRequest.Builder().index(firstIndex, secondIndex).timeout(t -> t.time("5s")).level(Level.Indices).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertYellowShards(response);
    assertEquals(response.indices().size(), 2);
    for (Map.Entry<String, IndexHealthStats> entry : response.indices().entrySet()) {
        assertYellowIndex(entry.getKey(), entry.getValue(), true);
    }
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Aggregations

OpenSearchClient (org.opensearch.client.opensearch.OpenSearchClient)19 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Test (org.junit.Test)8 OpenSearchTransport (org.opensearch.client.transport.OpenSearchTransport)7 List (java.util.List)5 Assert (org.junit.Assert)5 JsonData (org.opensearch.client.json.JsonData)5 PutClusterSettingsRequest (org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest)5 SearchResponse (org.opensearch.client.opensearch.core.SearchResponse)5 Alias (org.opensearch.client.opensearch.indices.Alias)5 CreateIndexResponse (org.opensearch.client.opensearch.indices.CreateIndexResponse)5 Arrays (java.util.Arrays)4 LogManager (java.util.logging.LogManager)4 Logger (java.util.logging.Logger)4 OpenSearchAsyncClient (org.opensearch.client.opensearch.OpenSearchAsyncClient)4 NodeStatistics (org.opensearch.client.opensearch._types.NodeStatistics)4 SortOrder (org.opensearch.client.opensearch._types.SortOrder)4 Aggregation (org.opensearch.client.opensearch._types.aggregations.Aggregation)4 Query (org.opensearch.client.opensearch._types.query_dsl.Query)4