Search in sources :

Example 1 with ElasticSearchIndex

use of core.framework.search.ElasticSearchIndex in project core-ng-project by neowu.

the class ElasticSearchIntegrationTest method indices.

@Test
void indices() {
    List<ElasticSearchIndex> indices = elasticSearch.indices();
    assertEquals(1, indices.size());
    ElasticSearchIndex index = indices.get(0);
    assertEquals("document", index.index);
    assertEquals(IndexMetaData.State.OPEN, index.state);
}
Also used : ElasticSearchIndex(core.framework.search.ElasticSearchIndex) IntegrationTest(core.framework.test.IntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ElasticSearchIndex

use of core.framework.search.ElasticSearchIndex in project core-ng-project by neowu.

the class CleanupOldIndexJobTest method index.

private ElasticSearchIndex index(String index, IndexMetaData.State state) {
    ElasticSearchIndex elasticSearchIndex = new ElasticSearchIndex();
    elasticSearchIndex.index = index;
    elasticSearchIndex.state = state;
    return elasticSearchIndex;
}
Also used : ElasticSearchIndex(core.framework.search.ElasticSearchIndex)

Example 3 with ElasticSearchIndex

use of core.framework.search.ElasticSearchIndex in project core-ng-project by neowu.

the class ElasticSearchImpl method indices.

@Override
public List<ElasticSearchIndex> indices() {
    StopWatch watch = new StopWatch();
    try {
        AdminClient adminClient = client().admin();
        ClusterStateResponse response = adminClient.cluster().state(new ClusterStateRequest().clear().metaData(true)).actionGet();
        ImmutableOpenMap<String, IndexMetaData> indices = response.getState().getMetaData().indices();
        List<ElasticSearchIndex> results = new ArrayList<>(indices.size());
        for (ObjectObjectCursor<String, IndexMetaData> cursor : indices) {
            IndexMetaData metaData = cursor.value;
            ElasticSearchIndex index = new ElasticSearchIndex();
            index.index = metaData.getIndex().getName();
            index.state = metaData.getState();
            results.add(index);
        }
        return results;
    } catch (ElasticsearchException e) {
        // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
        throw new SearchException(e);
    } finally {
        logger.info("indices, elapsedTime={}", watch.elapsedTime());
    }
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) ArrayList(java.util.ArrayList) SearchException(core.framework.search.SearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) StopWatch(core.framework.util.StopWatch) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ElasticSearchIndex(core.framework.search.ElasticSearchIndex) AdminClient(org.elasticsearch.client.AdminClient)

Aggregations

ElasticSearchIndex (core.framework.search.ElasticSearchIndex)3 SearchException (core.framework.search.SearchException)1 IntegrationTest (core.framework.test.IntegrationTest)1 StopWatch (core.framework.util.StopWatch)1 ArrayList (java.util.ArrayList)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 AdminClient (org.elasticsearch.client.AdminClient)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 Test (org.junit.jupiter.api.Test)1