Search in sources :

Example 1 with GetIndexRequest

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;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Example 2 with GetIndexRequest

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;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Example 3 with GetIndexRequest

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));
}
Also used : IndexResponse(org.opensearch.action.index.IndexResponse) GetRequest(org.opensearch.action.get.GetRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) IndexRequest(org.opensearch.action.index.IndexRequest) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) GetResponse(org.opensearch.action.get.GetResponse) DateTime(org.joda.time.DateTime)

Example 4 with GetIndexRequest

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());
}
Also used : GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) OpenSearchException(org.opensearch.OpenSearchException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with GetIndexRequest

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());
}
Also used : HashMap(java.util.HashMap) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) StringJoiner(java.util.StringJoiner)

Aggregations

GetIndexRequest (org.opensearch.client.indices.GetIndexRequest)9 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)5 HashMap (java.util.HashMap)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)4 GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)4 ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)4 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)4 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)4 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)4 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)4 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)4 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)4 UpdateSettingsRequest (org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest)4 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)4 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)4 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)4 CloseIndexRequest (org.opensearch.client.indices.CloseIndexRequest)4 CreateDataStreamRequest (org.opensearch.client.indices.CreateDataStreamRequest)4 DeleteAliasRequest (org.opensearch.client.indices.DeleteAliasRequest)4