Search in sources :

Example 1 with GetIndexResponse

use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fesen-httpclient by codelibs.

the class Elasticsearch7ClientTest method test_get_index.

@Test
void test_get_index() throws Exception {
    final String index = "test_get_index";
    final String alias = "test_alias";
    final XContentBuilder mappingBuilder = // 
    XContentFactory.jsonBuilder().startObject().startObject(// 
    "properties").startObject(// 
    "test_prop").field("type", // 
    "text").endObject().endObject().endObject();
    final String source = BytesReference.bytes(mappingBuilder).utf8ToString();
    CountDownLatch latch = new CountDownLatch(1);
    client.admin().indices().prepareCreate(index).execute().actionGet();
    client.admin().indices().prepareAliases().addAlias(index, alias).execute().actionGet();
    client.admin().indices().preparePutMapping(index).setSource(source, XContentType.JSON).execute().actionGet();
    client.admin().indices().prepareGetIndex().addIndices(index).execute(wrap(res -> {
        assertEquals(index, res.getIndices()[0]);
        assertTrue(res.getAliases().containsKey(index));
        assertTrue(res.getMappings().containsKey(index));
        assertTrue(res.getSettings().containsKey(index));
        latch.countDown();
    }, e -> {
        e.printStackTrace();
        try {
            fail();
        } finally {
            latch.countDown();
        }
    }));
    latch.await();
    {
        GetIndexResponse getIndexResponse = client.admin().indices().prepareGetIndex().addIndices(index).execute().actionGet();
        assertEquals(index, getIndexResponse.getIndices()[0]);
        assertTrue(getIndexResponse.getAliases().containsKey(index));
        assertTrue(getIndexResponse.getMappings().containsKey(index));
        assertTrue(getIndexResponse.getSettings().containsKey(index));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) DockerImageName(org.testcontainers.utility.DockerImageName) IndexResponse(org.opensearch.action.index.IndexResponse) SimpleFormatter(java.util.logging.SimpleFormatter) ToXContent(org.opensearch.common.xcontent.ToXContent) ClusterRerouteAction(org.opensearch.action.admin.cluster.reroute.ClusterRerouteAction) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) ClusterRerouteRequest(org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequest) ShrinkAction(org.opensearch.action.admin.indices.shrink.ShrinkAction) AfterAll(org.junit.jupiter.api.AfterAll) CloseIndexResponse(org.opensearch.action.admin.indices.close.CloseIndexResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Alias(org.opensearch.action.admin.indices.alias.Alias) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) XContentFactory(org.opensearch.common.xcontent.XContentFactory) SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) GetResponse(org.opensearch.action.get.GetResponse) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) PendingClusterTasksResponse(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksResponse) TimeValue(org.opensearch.common.unit.TimeValue) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse) SearchHit(org.opensearch.search.SearchHit) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) Result(org.opensearch.action.DocWriteResponse.Result) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) Settings(org.opensearch.common.settings.Settings) Logger(java.util.logging.Logger) RestStatus(org.opensearch.rest.RestStatus) StandardCharsets(java.nio.charset.StandardCharsets) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) Test(org.junit.jupiter.api.Test) ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) BytesArray(org.opensearch.common.bytes.BytesArray) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GetStoredScriptResponse(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) ActionListener.wrap(org.opensearch.action.ActionListener.wrap) XContentType(org.opensearch.common.xcontent.XContentType) CurlResponse(org.codelibs.curl.CurlResponse) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesReference(org.opensearch.common.bytes.BytesReference) UpdateResponse(org.opensearch.action.update.UpdateResponse) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder) Level(java.util.logging.Level) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) AnalyzeAction(org.opensearch.action.admin.indices.analyze.AnalyzeAction) DeleteResponse(org.opensearch.action.delete.DeleteResponse) AliasesExistResponse(org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) GenericContainer(org.testcontainers.containers.GenericContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchResponse(org.opensearch.action.search.SearchResponse) SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) OutputStream(java.io.OutputStream) QueryBuilders(org.opensearch.index.query.QueryBuilders) ExplainResponse(org.opensearch.action.explain.ExplainResponse) FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) GetAliasesResponse(org.opensearch.action.admin.indices.alias.get.GetAliasesResponse) MainAction(org.opensearch.action.main.MainAction) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) MainRequest(org.opensearch.action.main.MainRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Curl(org.codelibs.curl.Curl) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) AfterEach(org.junit.jupiter.api.AfterEach) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) BulkResponse(org.opensearch.action.bulk.BulkResponse) MainResponse(org.opensearch.action.main.MainResponse) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) HttpNodesStatsAction(org.codelibs.fesen.client.action.HttpNodesStatsAction) ConsoleHandler(java.util.logging.ConsoleHandler) IndicesExistsResponse(org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse) MultiGetRequestBuilder(org.opensearch.action.get.MultiGetRequestBuilder) ClearIndicesCacheResponse(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) CountDownLatch(java.util.concurrent.CountDownLatch) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with GetIndexResponse

use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fesen-httpclient by codelibs.

the class HttpGetIndexAction method execute.

public void execute(final GetIndexRequest request, final ActionListener<GetIndexResponse> listener) {
    getCurlRequest(request).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final GetIndexResponse getIndexResponse = GetIndexResponse.fromXContent(parser);
            listener.onResponse(getIndexResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 3 with GetIndexResponse

use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fess-suggest by codelibs.

the class SuggesterTest method test_switchIndex.

@Test
public void test_switchIndex() throws Exception {
    SuggestItem[] items = getItemSet1();
    suggester.indexer().index(items);
    suggester.refresh();
    SuggestResponse response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
    assertEquals(1, response.getNum());
    assertEquals("検索 エンジン", response.getWords().get(0));
    SuggestResponse response2 = suggester.suggest().setSuggestDetail(true).execute().getResponse();
    assertEquals(2, response2.getNum());
    Thread.sleep(1000);
    suggester.createNextIndex();
    SuggestItem[] items2 = getItemSet2();
    suggester.indexer().index(items2);
    suggester.refresh();
    response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
    assertEquals(1, response.getNum());
    assertEquals("検索 エンジン", response.getWords().get(0));
    response2 = suggester.suggest().setSuggestDetail(true).execute().getResponse();
    assertEquals(2, response2.getNum());
    suggester.switchIndex();
    response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
    assertEquals(0, response.getNum());
    response = suggester.suggest().setSuggestDetail(true).execute().getResponse();
    assertEquals(3, response.getNum());
    response2 = suggester.suggest().setQuery("-a").setSuggestDetail(true).execute().getResponse();
    assertEquals(2, response2.getNum());
    SuggestResponse response3 = suggester.suggest().setQuery("-aa-").setSuggestDetail(true).execute().getResponse();
    assertEquals(1, response3.getNum());
    GetIndexResponse getIndexResponse = runner.client().admin().indices().prepareGetIndex().execute().actionGet();
    int count = 0;
    for (String index : getIndexResponse.getIndices()) {
        if (index.startsWith(suggester.getIndex())) {
            count++;
        }
    }
    assertEquals(2, count);
    suggester.removeDisableIndices();
    response = suggester.suggest().setSuggestDetail(true).execute().getResponse();
    assertEquals(3, response.getNum());
    getIndexResponse = runner.client().admin().indices().prepareGetIndex().execute().actionGet();
    count = 0;
    for (String index : getIndexResponse.getIndices()) {
        if (index.startsWith(suggester.getIndex())) {
            count++;
        }
    }
    assertEquals(1, count);
}
Also used : GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) SuggestItem(org.codelibs.fess.suggest.entity.SuggestItem) SuggestResponse(org.codelibs.fess.suggest.request.suggest.SuggestResponse) Test(org.junit.Test)

Example 4 with GetIndexResponse

use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fess-suggest by codelibs.

the class Suggester method removeDisableIndices.

public void removeDisableIndices() {
    final GetIndexResponse response = client.admin().indices().prepareGetIndex().addIndices("*").execute().actionGet(suggestSettings.getIndicesTimeout());
    Stream.of(response.getIndices()).filter(s -> {
        if (!isSuggestIndex(s)) {
            return false;
        }
        final List<AliasMetadata> list = response.getAliases().get(s);
        if (list == null) {
            return true;
        }
        return list.isEmpty();
    }).forEach(s -> {
        if (logger.isInfoEnabled()) {
            logger.info("Delete index: {}", s);
        }
        client.admin().indices().prepareDelete(s).execute().actionGet(suggestSettings.getIndicesTimeout());
    });
}
Also used : IndicesAliasesRequestBuilder(org.opensearch.action.admin.indices.alias.IndicesAliasesRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Normalizer(org.codelibs.fess.suggest.normalizer.Normalizer) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) ReadingConverter(org.codelibs.fess.suggest.converter.ReadingConverter) SuggestRequestBuilder(org.codelibs.fess.suggest.request.suggest.SuggestRequestBuilder) FieldNames(org.codelibs.fess.suggest.constants.FieldNames) ArrayList(java.util.ArrayList) Alias(org.opensearch.action.admin.indices.alias.Alias) SearchResponse(org.opensearch.action.search.SearchResponse) ExecutorService(java.util.concurrent.ExecutorService) QueryBuilders(org.opensearch.index.query.QueryBuilders) Client(org.opensearch.client.Client) SuggestAnalyzer(org.codelibs.fess.suggest.analysis.SuggestAnalyzer) GetAliasesResponse(org.opensearch.action.admin.indices.alias.get.GetAliasesResponse) StringUtil(org.codelibs.core.lang.StringUtil) SuggestIndexer(org.codelibs.fess.suggest.index.SuggestIndexer) IOException(java.io.IOException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) SuggestConstants(org.codelibs.fess.suggest.constants.SuggestConstants) InputStreamReader(java.io.InputStreamReader) PopularWordsRequestBuilder(org.codelibs.fess.suggest.request.popularwords.PopularWordsRequestBuilder) SuggestSettings(org.codelibs.fess.suggest.settings.SuggestSettings) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) QueryBuilder(org.opensearch.index.query.QueryBuilder) SuggesterException(org.codelibs.fess.suggest.exception.SuggesterException) DateTimeFormatter(java.time.format.DateTimeFormatter) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) XContentType(org.opensearch.common.xcontent.XContentType) BufferedReader(java.io.BufferedReader) IndicesExistsResponse(org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse) LogManager(org.apache.logging.log4j.LogManager) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with GetIndexResponse

use of org.opensearch.action.admin.indices.get.GetIndexResponse in project OpenSearch by opensearch-project.

the class OpenSearchIntegTestCase method resolveCustomDataPath.

public static String resolveCustomDataPath(String index) {
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get();
    assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index));
    return getIndexResponse.getSettings().get(index).get(IndexMetadata.SETTING_DATA_PATH);
}
Also used : GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse)

Aggregations

GetIndexResponse (org.opensearch.action.admin.indices.get.GetIndexResponse)11 Alias (org.opensearch.action.admin.indices.alias.Alias)4 GetAliasesResponse (org.opensearch.action.admin.indices.alias.get.GetAliasesResponse)4 CreateIndexResponse (org.opensearch.action.admin.indices.create.CreateIndexResponse)4 IndicesExistsResponse (org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConsoleHandler (java.util.logging.ConsoleHandler)3 Level (java.util.logging.Level)3 Logger (java.util.logging.Logger)3 SimpleFormatter (java.util.logging.SimpleFormatter)3 Curl (org.codelibs.curl.Curl)3 CurlResponse (org.codelibs.curl.CurlResponse)3 HttpNodesStatsAction (org.codelibs.fesen.client.action.HttpNodesStatsAction)3 AfterAll (org.junit.jupiter.api.AfterAll)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2