use of org.opensearch.client.indices.GetIndexRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method indicesExist.
static Request indicesExist(GetIndexRequest getIndexRequest) {
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {
throw new IllegalArgumentException("indices are mandatory");
}
String endpoint = RequestConverters.endpoint(getIndexRequest.indices(), "");
Request request = new Request(HttpHead.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withLocal(getIndexRequest.local());
params.withHuman(getIndexRequest.humanReadable());
params.withIndicesOptions(getIndexRequest.indicesOptions());
params.withIncludeDefaults(getIndexRequest.includeDefaults());
request.addParameters(params.asMap());
return request;
}
use of org.opensearch.client.indices.GetIndexRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method getIndex.
static Request getIndex(GetIndexRequest getIndexRequest) {
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
String endpoint = RequestConverters.endpoint(indices);
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withIndicesOptions(getIndexRequest.indicesOptions());
params.withLocal(getIndexRequest.local());
params.withIncludeDefaults(getIndexRequest.includeDefaults());
params.withHuman(getIndexRequest.humanReadable());
params.withMasterTimeout(getIndexRequest.masterNodeTimeout());
request.addParameters(params.asMap());
return request;
}
use of org.opensearch.client.indices.GetIndexRequest in project OpenSearch by opensearch-project.
the class CrudIT method testUrlEncode.
public void testUrlEncode() throws IOException {
String indexPattern = "<logstash-{now/M}>";
String expectedIndex = "logstash-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(DateTimeZone.UTC).monthOfYear().roundFloorCopy());
{
IndexRequest indexRequest = new IndexRequest(indexPattern).id("id#1");
indexRequest.source("field", "value");
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
assertEquals(expectedIndex, indexResponse.getIndex());
assertEquals("id#1", indexResponse.getId());
}
{
GetRequest getRequest = new GetRequest(indexPattern, "id#1");
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
assertTrue(getResponse.isExists());
assertEquals(expectedIndex, getResponse.getIndex());
assertEquals("id#1", getResponse.getId());
}
String docId = "this/is/the/id/中文";
{
IndexRequest indexRequest = new IndexRequest("index").id(docId);
indexRequest.source("field", "value");
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
assertEquals("index", indexResponse.getIndex());
assertEquals(docId, indexResponse.getId());
}
{
GetRequest getRequest = new GetRequest("index", docId);
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
assertTrue(getResponse.isExists());
assertEquals("index", getResponse.getIndex());
assertEquals(docId, getResponse.getId());
}
assertTrue(highLevelClient().indices().exists(new GetIndexRequest(indexPattern, "index"), RequestOptions.DEFAULT));
}
use of org.opensearch.client.indices.GetIndexRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testGetIndexNonExistentIndex.
public void testGetIndexNonExistentIndex() throws IOException {
String nonExistentIndex = "index_that_doesnt_exist";
assertFalse(indexExists(nonExistentIndex));
GetIndexRequest getIndexRequest = new GetIndexRequest(nonExistentIndex);
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
}
use of org.opensearch.client.indices.GetIndexRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method testGetIndex.
public void testGetIndex() throws IOException {
String[] indicesUnderTest = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
GetIndexRequest getIndexRequest = new GetIndexRequest(indicesUnderTest);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomMasterTimeout(getIndexRequest, expectedParams);
RequestConvertersTests.setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
RequestConvertersTests.setRandomLocal(getIndexRequest::local, expectedParams);
RequestConvertersTests.setRandomHumanReadable(getIndexRequest::humanReadable, expectedParams);
if (OpenSearchTestCase.randomBoolean()) {
// the request object will not have include_defaults present unless it is set to
// true
getIndexRequest.includeDefaults(OpenSearchTestCase.randomBoolean());
if (getIndexRequest.includeDefaults()) {
expectedParams.put("include_defaults", Boolean.toString(true));
}
}
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indicesUnderTest != null && indicesUnderTest.length > 0) {
endpoint.add(String.join(",", indicesUnderTest));
}
Request request = IndicesRequestConverters.getIndex(getIndexRequest);
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
Assert.assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
Assert.assertThat(request.getEntity(), nullValue());
}
Aggregations