org.elasticsearch.client.ClusterAdminClient Java Examples
The following examples show how to use
org.elasticsearch.client.ClusterAdminClient.
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: UpdateMappingFieldDemo.java From javabase with Apache License 2.0 | 6 votes |
private static void update() { try { IndicesAdminClient indicesAdminClient = client.admin().indices(); if (indicesAdminClient.prepareExists(INDEX_NAME_v2).execute().actionGet().isExists()) { indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v2)).actionGet(); } indicesAdminClient.prepareCreate(INDEX_NAME_v2).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet(); //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); //0、更新mapping updateMapping(); //1、更新数据 reindexData(indicesAdminClient); //2、realias 重新建立连接 indicesAdminClient.prepareAliases().removeAlias(INDEX_NAME_v1, ALIX_NAME).addAlias(INDEX_NAME_v2, ALIX_NAME).execute().actionGet(); }catch (Exception e){ log.error("beforeUpdate error:{}"+e.getLocalizedMessage()); } }
Example #2
Source File: UpdateMappingFieldDemo.java From javabase with Apache License 2.0 | 6 votes |
private static void beforeUpdate() { try { IndicesAdminClient indicesAdminClient = client.admin().indices(); indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v1)).actionGet(); if (!indicesAdminClient.prepareExists(INDEX_NAME_v1).execute().actionGet().isExists()) { indicesAdminClient.prepareCreate(INDEX_NAME_v1).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet(); } //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); //创建别名alias indicesAdminClient.prepareAliases().addAlias(INDEX_NAME_v1, ALIX_NAME).execute().actionGet(); prepareData(indicesAdminClient); }catch (Exception e){ log.error("beforeUpdate error:{}"+e.getLocalizedMessage()); } }
Example #3
Source File: CrudDemo.java From javabase with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { index(); //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); // analyze(); } catch (Exception e) { log.error("main error:{}", e.getMessage()); }finally { client.close(); } }
Example #4
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 #5
Source File: GathererRequestBuilder.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
public GathererRequestBuilder(ClusterAdminClient clusterClient) { super((InternalClusterAdminClient) clusterClient, new GathererRequest()); }
Example #6
Source File: GathererRequestBuilder.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
@Override protected void doExecute(ActionListener<GathererResponse> listener) { ((ClusterAdminClient) client).execute(GathererAction.INSTANCE, request, listener); }
Example #7
Source File: GathererAction.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
@Override public GathererRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new GathererRequestBuilder(client); }
Example #8
Source File: DeployAction.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
@Override public DeployRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new DeployRequestBuilder(client); }
Example #9
Source File: DeployRequestBuilder.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
public DeployRequestBuilder(ClusterAdminClient clusterClient) { super((InternalClusterAdminClient) clusterClient, new DeployRequest()); }
Example #10
Source File: DeployRequestBuilder.java From elasticsearch-gatherer with Apache License 2.0 | 4 votes |
@Override protected void doExecute(ActionListener<DeployResponse> listener) { ((ClusterAdminClient) client).execute(DeployAction.INSTANCE, request, listener); }
Example #11
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 #12
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public ClusterAdminClient cluster() { return clusterAdmin; }