本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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();
}
示例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();
}