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);
}
}
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());
}
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
}
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);
}
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);
}
}
Aggregations