當前位置: 首頁>>代碼示例>>Java>>正文


Java AdminClient類代碼示例

本文整理匯總了Java中org.elasticsearch.client.AdminClient的典型用法代碼示例。如果您正苦於以下問題:Java AdminClient類的具體用法?Java AdminClient怎麽用?Java AdminClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AdminClient類屬於org.elasticsearch.client包,在下文中一共展示了AdminClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateIndexWithoutSettings

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testCreateIndexWithoutSettings() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:24,代碼來源:ElasticsearchClientWrapperImplTest.java

示例2: testCreateIndex

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testCreateIndex() {
    // Test data
    final String indexName = "Index_Name";
    final Map<String, Object> settings = Collections.singletonMap("settings_key", "settings_value");
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.setSettings(settings)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName, settings);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例3: testRefreshIndex

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testRefreshIndex() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final RefreshRequestBuilder refreshRequestBuilder = createMock(RefreshRequestBuilder.class);
    final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareRefresh(indexName)).andReturn(refreshRequestBuilder);
    expect(refreshRequestBuilder.get()).andReturn(createMock(RefreshResponse.class));
    // Replay
    replayAll();
    // Run test scenario
    elasticsearchClientWrapper.refreshIndex(indexName);
    // Verify
    verifyAll();
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:23,代碼來源:ElasticsearchClientWrapperImplTest.java

示例4: testAddAlias

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testAddAlias() {
    //Test data
    final String indexName = "index";
    final String aliasName = "alias";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesAliasesRequestBuilder indicesAliasesRequestBuilder = createMock(IndicesAliasesRequestBuilder.class);
    final IndicesAliasesResponse indicesAliasesResponse = createMock(IndicesAliasesResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareAliases()).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.addAlias(indexName, aliasName)).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.get()).andReturn(indicesAliasesResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.addAlias(indexName, aliasName);
    //Verify
    verifyAll();
    assertEquals(indicesAliasesResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例5: testDeleteIndex

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testDeleteIndex() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final DeleteIndexRequestBuilder deleteIndexRequestBuilder = createMock(DeleteIndexRequestBuilder.class);
    final DeleteIndexResponse deleteIndexResponse = createMock(DeleteIndexResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareDelete(indexName)).andReturn(deleteIndexRequestBuilder);
    expect(deleteIndexRequestBuilder.get()).andReturn(deleteIndexResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.deleteIndex(indexName);
    //Verify
    verifyAll();
    assertEquals(deleteIndexResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:24,代碼來源:ElasticsearchClientWrapperImplTest.java

示例6: testIndexExists

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testIndexExists() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesExistsRequestBuilder indicesExistsRequestBuilder = createMock(IndicesExistsRequestBuilder.class);
    final IndicesExistsResponse indicesExistsResponse = createMock(IndicesExistsResponse.class);
    final boolean exists = new Random().nextBoolean();
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareExists(indexName)).andReturn(indicesExistsRequestBuilder);
    expect(indicesExistsRequestBuilder.get()).andReturn(indicesExistsResponse);
    expect(indicesExistsResponse.isExists()).andReturn(exists);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.indexExists(indexName);
    //Verify
    verifyAll();
    assertEquals(exists, result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:26,代碼來源:ElasticsearchClientWrapperImplTest.java

示例7: deleteIndex

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
/**
 * 刪除索引
 * 
 * @param index_type
 */
public boolean deleteIndex(String index_type) {
    try {
        AdminClient adminClient = ESClient.getClient().admin();
        if (adminClient.indices().prepareExists(index_type).execute().actionGet().isExists()) {
            ESClient.getClient().admin().indices().delete(new DeleteIndexRequest(index_type));
        }
        if (adminClient.indices().prepareExists(index_type + "_1").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_1"));
        }
        if (adminClient.indices().prepareExists(index_type + "_2").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_2"));
        }
        return true;
    } catch (Exception e) {
        log.error("delete index fail,indexname:{}", index_type);
    }
    return false;
}
 
開發者ID:hailin0,項目名稱:es-service-parent,代碼行數:28,代碼來源:IndexTransaction.java

示例8: main

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
public static void main(String[] args)
{
	Node node = nodeBuilder().node();
	Client client = node.client();

	AdminClient ac = client.admin();

	client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
	ElasticTest t = new ElasticTest();
	t.initRiver(client);
	// t.initRiver(client);
	// t.getContributionsByCandName(client, "aaew_corpus_aaew_full", 0);
	t.search(client);
	// // on shutdown
	// // Configuration
	// ClientConfig clientConfig = new
	// ClientConfig.Builder("http://localhost:9200").multiThreaded(true).build();
	//
	// // Construct a new Jest client according to configuration via factory
	// JestClientFactory factory = new JestClientFactory();
	// factory.setClientConfig(clientConfig);
	// JestClient clientj = factory.getObject();
	// clientj.
	node.close();

}
 
開發者ID:cplutte,項目名稱:bts,代碼行數:27,代碼來源:ElasticTest.java

示例9: setup

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
/**
 * @param indices The names of all indices that will exist.
 * @param mappings The index mappings.
 * @return An object to test.
 */
public ElasticsearchColumnMetadataDao setup(
        String[] indices,
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {

  AdminClient adminClient = mock(AdminClient.class);
  IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
  GetIndexRequestBuilder getIndexRequestBuilder = mock(GetIndexRequestBuilder.class);
  GetIndexResponse getIndexResponse = mock(GetIndexResponse.class);
  ActionFuture getMappingsActionFuture = mock(ActionFuture.class);
  GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class);

  // setup the mocks so that a set of indices are available to the DAO
  when(adminClient.indices()).thenReturn(indicesAdminClient);
  when(indicesAdminClient.prepareGetIndex()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.setFeatures()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.get()).thenReturn(getIndexResponse);
  when(getIndexResponse.getIndices()).thenReturn(indices);

  // setup the mocks so that a set of mappings are available to the DAO
  when(indicesAdminClient.getMappings(any())).thenReturn(getMappingsActionFuture);
  when(getMappingsActionFuture.actionGet()).thenReturn(getMappingsResponse);
  when(getMappingsResponse.getMappings()).thenReturn(mappings);

  return new ElasticsearchColumnMetadataDao(adminClient);
}
 
開發者ID:apache,項目名稱:metron,代碼行數:31,代碼來源:ElasticsearchColumnMetadataDaoTest.java

示例10: SetupMocks

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
private void SetupMocks(Client client, IndicesAdminClient indicesAdminClient, ImmutableOpenMap<String, IndexMetaData> indicesMap) {
	AdminClient adminClient = mock(AdminClient.class);
	ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);
	
	@SuppressWarnings("unchecked")
	ActionFuture<ClusterStateResponse> actionFuture = ((ActionFuture<ClusterStateResponse>) mock(ActionFuture.class));
	ClusterStateResponse response = mock(ClusterStateResponse.class);
	ClusterState state = mock(ClusterState.class);
	MetaData metaData = mock(MetaData.class);
	
	when(client.admin()).thenReturn(adminClient);
	when(adminClient.indices()).thenReturn(indicesAdminClient);
	when(adminClient.cluster()).thenReturn(clusterAdminClient);
	when(clusterAdminClient.state(Mockito.any(ClusterStateRequest.class))).thenReturn(actionFuture);
	when(actionFuture.actionGet()).thenReturn(response);
	when(response.getState()).thenReturn(state);
	when(state.getMetaData()).thenReturn(metaData);
	when(metaData.getIndices()).thenReturn(indicesMap);
}
 
開發者ID:cternes,項目名稱:alfa,代碼行數:20,代碼來源:LogCleanerTest.java

示例11: testPutMapping

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
@Test
public void testPutMapping() {
    // Test data
    final String indexName = "Index_Name";
    final String documentType = "documentType";
    final String mappings = "mappings";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final PutMappingRequestBuilder putMappingRequestBuilder = createMock(PutMappingRequestBuilder.class);
    final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.preparePutMapping(indexName)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.setType(documentType)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.setSource(mappings)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.get()).andReturn(putMappingResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.putMapping(indexName, documentType, mappings);
    // Verify
    verifyAll();
    assertEquals(putMappingResponse.isAcknowledged(), result);
}
 
開發者ID:Biacode,項目名稱:escommons,代碼行數:28,代碼來源:ElasticsearchClientWrapperImplTest.java

示例12: isIndexingRunning

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
private static boolean isIndexingRunning(AdminClient client, String indexName) {
    IndicesStatsResponse indicesStatsResponse = client.indices()
                                                      .prepareStats(indexName)
                                                      .all()
                                                      .execute()
                                                      .actionGet();

    return indicesStatsResponse.getTotal().getIndexing().getTotal().getIndexCurrent() > INTEGER_ZERO;
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:10,代碼來源:Indexer.java

示例13: refresh

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
private static boolean refresh(String index) {
    try {
        AdminClient adminClient = client.getClient().admin();
        RefreshRequestBuilder refreshRequestBuilder = adminClient.indices().prepareRefresh(index);
        adminClient.indices().refresh(refreshRequestBuilder.request()).actionGet();
        return true;
    } catch (IndexMissingException t) {
        // Ignore, as means that no traces have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("Index [%s] not found, unable to proceed.", index);
        }
        return false;
    }
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:16,代碼來源:AnalyticsServiceElasticsearch.java

示例14: indexExists

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
/**
 * Checks if a given index exists in elastic
 * <p/>
 * @param client
 * @param indexName
 * @return
 */
private boolean indexExists(Client client, String indexName) {
  AdminClient admin = client.admin();
  IndicesAdminClient indices = admin.indices();

  IndicesExistsRequestBuilder indicesExistsRequestBuilder = indices.
      prepareExists(indexName);

  IndicesExistsResponse response = indicesExistsRequestBuilder
      .execute()
      .actionGet();

  return response.isExists();
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:21,代碼來源:ElasticController.java

示例15: typeExists

import org.elasticsearch.client.AdminClient; //導入依賴的package包/類
/**
 * Checks if a given data type exists. It is a given that the index exists
 * <p/>
 * @param client
 * @param typeName
 * @return
 */
private boolean typeExists(Client client, String indexName, String typeName) {
  AdminClient admin = client.admin();
  IndicesAdminClient indices = admin.indices();

  ActionFuture<TypesExistsResponse> action = indices.typesExists(
      new TypesExistsRequest(
          new String[]{indexName}, typeName));

  TypesExistsResponse response = action.actionGet();

  return response.isExists();
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:20,代碼來源:ElasticController.java


注:本文中的org.elasticsearch.client.AdminClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。