org.elasticsearch.client.AdminClient Java Examples
The following examples show how to use
org.elasticsearch.client.AdminClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexTransaction.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 删除索引 * * @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; }
Example #2
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #3
Source File: EsEntityIndexImpl.java From usergrid with Apache License 2.0 | 5 votes |
private void addAlias(String indexName) { Timer.Context timer = updateAliasTimer.time(); try { Boolean isAck; final AdminClient adminClient = esProvider.getClient().admin(); String[] indexNames = getIndexes(AliasType.Write); int count = 0; IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases(); for (String currentIndex : indexNames) { aliasesRequestBuilder.removeAlias(currentIndex, alias.getWriteAlias()); count++; } if (count > 0) { isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged(); logger.info("Removed Index Name from Alias=[{}] ACK=[{}]", alias, isAck); } aliasesRequestBuilder = adminClient.indices().prepareAliases(); //Added For Graphite Metrics //add write alias aliasesRequestBuilder.addAlias(indexName, alias.getWriteAlias()); //Added For Graphite Metrics // add read alias aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias()); isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged(); logger.info("Created new read and write aliases ACK=[{}]", isAck); aliasCache.invalidate(alias); } catch (Exception e) { logger.warn("Failed to create alias ", e); } finally { timer.stop(); } }
Example #4
Source File: EsIndexCacheImpl.java From usergrid with Apache License 2.0 | 5 votes |
private String[] getIndexesFromEs(final String aliasName){ final AdminClient adminClient = this.provider.getClient().admin(); //remove write alias, can only have one ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = adminClient.indices().getAliases( new GetAliasesRequest( aliasName ) ).actionGet().getAliases(); return aliasMap.keys().toArray( String.class ); }
Example #5
Source File: AnalyticsServiceElasticsearch.java From hawkular-apm with Apache License 2.0 | 5 votes |
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; } }
Example #6
Source File: ElasticsearchResource.java From vertexium with Apache License 2.0 | 5 votes |
public void dropIndices() throws Exception { AdminClient client = getClient().admin(); String[] indices = client.indices().prepareGetIndex().execute().get().indices(); for (String index : indices) { if (index.startsWith(ES_INDEX_NAME) || index.startsWith(ES_EXTENDED_DATA_INDEX_NAME_PREFIX)) { LOGGER.info("deleting test index: %s", index); client.indices().prepareDelete(index).execute().actionGet(); } } }
Example #7
Source File: ElasticsearchResource.java From vertexium with Apache License 2.0 | 5 votes |
public void dropIndices() throws Exception { AdminClient client = getClient().admin(); String[] indices = client.indices().prepareGetIndex().execute().get().indices(); for (String index : indices) { if (index.startsWith(ES_INDEX_NAME) || index.startsWith(ES_EXTENDED_DATA_INDEX_NAME_PREFIX)) { LOGGER.info("deleting test index: %s", index); client.indices().prepareDelete(index).execute().actionGet(); } } }
Example #8
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #9
Source File: AdminOperationsTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private IndicesAdminClient mockedIndicesAdminClient(BulkProcessorObjectFactory factory) { ClientProvider clientProvider = mock(ClientProvider.class); when(factory.getClientProvider()).thenReturn(clientProvider); TransportClient transportClient = PowerMockito.mock(TransportClient.class); when(clientProvider.createClient()).thenReturn(transportClient); AdminClient adminClient = mock(AdminClient.class); when(transportClient.admin()).thenReturn(adminClient); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); when(adminClient.indices()).thenReturn(indicesAdminClient); return indicesAdminClient; }
Example #10
Source File: ClientWithStats.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public AdminClient admin() { return wrapped.admin(); }
Example #11
Source File: FessEsClient.java From fess with Apache License 2.0 | 4 votes |
@Override public AdminClient admin() { return client.admin(); }
Example #12
Source File: RolloverTests.java From anomaly-detection with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); Client client = mock(Client.class); indicesClient = mock(IndicesAdminClient.class); AdminClient adminClient = mock(AdminClient.class); clusterService = mock(ClusterService.class); ClusterSettings clusterSettings = new ClusterSettings( Settings.EMPTY, Collections .unmodifiableSet( new HashSet<>( Arrays .asList( AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD ) ) ) ); clusterName = new ClusterName("test"); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); ThreadPool threadPool = mock(ThreadPool.class); Settings settings = Settings.EMPTY; when(client.admin()).thenReturn(adminClient); when(adminClient.indices()).thenReturn(indicesClient); adIndices = new AnomalyDetectionIndices(client, clusterService, threadPool, settings); clusterAdminClient = mock(ClusterAdminClient.class); when(adminClient.cluster()).thenReturn(clusterAdminClient); doAnswer(invocation -> { ClusterStateRequest clusterStateRequest = invocation.getArgument(0); assertEquals(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, clusterStateRequest.indices()[0]); @SuppressWarnings("unchecked") ActionListener<ClusterStateResponse> listener = (ActionListener<ClusterStateResponse>) invocation.getArgument(1); listener.onResponse(new ClusterStateResponse(clusterName, clusterState, true)); return null; }).when(clusterAdminClient).state(any(), any()); }
Example #13
Source File: ElasticsearchEmitterTest.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Set the 2nd record in the passed in list to fail. * * Assert that only 1 record is returned, and that it is equal to the 2nd object in the list. * * @throws IOException */ @Test public void testRecordFails() throws IOException { List<ElasticsearchObject> records = new ArrayList<ElasticsearchObject>(); ElasticsearchObject r1 = createMockRecordAndSetExpectations("sample-index", "type", "1", "{\"name\":\"Mike\"}"); records.add(r1); // this will be the failing record. ElasticsearchObject r2 = createMockRecordAndSetExpectations("sample-index", "type", "2", "{\"name\":\"Mike\",\"badJson\":\"forgotendingquote}"); records.add(r2); ElasticsearchObject r3 = createMockRecordAndSetExpectations("sample-index", "type", "3", "{\"name\":\"Mike\"}"); records.add(r3); // mock building and executing the request mockBuildingAndExecutingRequest(records); // Verify that there is a response for each record, and that each gets touched. BulkItemResponse[] responses = new BulkItemResponse[records.size()]; for (int i = 0; i < responses.length; i++) { responses[i] = createMock(BulkItemResponse.class); // define behavior for a failing record if (i == 1) { expect(responses[i].isFailed()).andReturn(true); expect(responses[i].getFailureMessage()).andReturn("bad json error message"); Failure failure = new Failure("index", "type", "id", "foo failure message", RestStatus.BAD_REQUEST); expect(responses[i].getFailure()).andReturn(failure); } else { expect(responses[i].isFailed()).andReturn(false); } replay(responses[i]); } // verify admin client gets used to check cluster status. this case, yellow expect(mockBulkResponse.getItems()).andReturn(responses); AdminClient mockAdminClient = createMock(AdminClient.class); expect(elasticsearchClientMock.admin()).andReturn(mockAdminClient); ClusterAdminClient mockClusterAdminClient = createMock(ClusterAdminClient.class); expect(mockAdminClient.cluster()).andReturn(mockClusterAdminClient); ClusterHealthRequestBuilder mockHealthRequestBuilder = createMock(ClusterHealthRequestBuilder.class); expect(mockClusterAdminClient.prepareHealth()).andReturn(mockHealthRequestBuilder); ListenableActionFuture mockHealthFuture = createMock(ListenableActionFuture.class); expect(mockHealthRequestBuilder.execute()).andReturn(mockHealthFuture); ClusterHealthResponse mockResponse = createMock(ClusterHealthResponse.class); expect(mockHealthFuture.actionGet()).andReturn(mockResponse); expect(mockResponse.getStatus()).andReturn(ClusterHealthStatus.YELLOW); expectLastCall().times(2); replay(elasticsearchClientMock, r1, r2, r3, buffer, mockBulkBuilder, mockIndexBuilder, mockFuture, mockBulkResponse, mockAdminClient, mockClusterAdminClient, mockHealthRequestBuilder, mockHealthFuture, mockResponse); List<ElasticsearchObject> failures = emitter.emit(buffer); assertTrue(failures.size() == 1); // the emitter should return the exact object that failed assertEquals(failures.get(0), records.get(1)); verify(elasticsearchClientMock, r1, r2, r3, buffer, mockBulkBuilder, mockIndexBuilder, mockFuture, mockBulkResponse, mockAdminClient, mockClusterAdminClient, mockHealthRequestBuilder, mockHealthFuture, mockResponse); verifyRecords(records); verifyResponses(responses); }
Example #14
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public final AdminClient admin() { return admin; }
Example #15
Source File: DefaultElasticSearchAdminService.java From vertx-elasticsearch-service with Apache License 2.0 | 2 votes |
/** * Returns the inner admin client * * @return */ @Override public AdminClient getAdmin() { return service.getClient().admin(); }
Example #16
Source File: InternalElasticSearchAdminService.java From vertx-elasticsearch-service with Apache License 2.0 | 2 votes |
/** * Returns the inner admin client * * @return */ @ProxyIgnore AdminClient getAdmin();
Example #17
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 2 votes |
/** * Return an elasticsearch admin client. * * @return admin client */ public AdminClient admin() { return client().admin(); }
Example #18
Source File: ESIntegTestCase.java From crate with Apache License 2.0 | 2 votes |
/** * Returns a random admin client. This client can either be a node or a transport client pointing to any of * the nodes in the cluster. */ protected AdminClient admin() { return client().admin(); }