Java Code Examples for org.elasticsearch.client.Client

The following are top voted examples for showing how to use org.elasticsearch.client.Client. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: elasticsearch_my   File: BlobStoreRepositoryTests.java   Source Code and License 7 votes vote down vote up
private BlobStoreRepository setupRepo() {
    final Client client = client();
    final Path location = ESIntegTestCase.randomRepoPath(node().settings());
    final String repositoryName = "test-repo";

    PutRepositoryResponse putRepositoryResponse =
        client.admin().cluster().preparePutRepository(repositoryName)
                                .setType("fs")
                                .setSettings(Settings.builder().put(node().settings()).put("location", location))
                                .get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    final RepositoriesService repositoriesService = getInstanceFromNode(RepositoriesService.class);
    @SuppressWarnings("unchecked") final BlobStoreRepository repository =
        (BlobStoreRepository) repositoriesService.repository(repositoryName);
    return repository;
}
 
Example 2
Project: Elasticsearch   File: RestFlushAction.java   Source Code and License 7 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    flushRequest.indicesOptions(IndicesOptions.fromRequest(request, flushRequest.indicesOptions()));
    flushRequest.force(request.paramAsBoolean("force", flushRequest.force()));
    flushRequest.waitIfOngoing(request.paramAsBoolean("wait_if_ongoing", flushRequest.waitIfOngoing()));
    client.admin().indices().flush(flushRequest, new RestBuilderListener<FlushResponse>(channel) {
        @Override
        public RestResponse buildResponse(FlushResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 3
Project: elasticsearch_my   File: TribeUnitTests.java   Source Code and License 7 votes vote down vote up
private static void assertTribeNodeSuccessfullyCreated(Settings extraSettings) throws Exception {
    //The tribe clients do need it to make sure they can find their corresponding tribes using the proper transport
    Settings settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put("node.name", "tribe_node")
            .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put("discovery.type", "local")
            .put("tribe.t1.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put("tribe.t2.transport.type",MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(extraSettings).build();

    try (Node node = new MockNode(settings, Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class)).start()) {
        try (Client client = node.client()) {
            assertBusy(() -> {
                ClusterState state = client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
                assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
                assertThat(state.getNodes().getSize(), equalTo(5));
                for (DiscoveryNode discoveryNode : state.getNodes()) {
                    assertThat(discoveryNode.getName(), either(equalTo("tribe1_node")).or(equalTo("tribe2_node"))
                            .or(equalTo("tribe_node")).or(equalTo("tribe_node/t1")).or(equalTo("tribe_node/t2")));
                }
            });
        }
    }
}
 
Example 4
Project: elasticsearch   File: App.java   Source Code and License 7 votes vote down vote up
private static void deleteES(Client client) {
  BulkRequestBuilder bulkRequest = client.prepareBulk();
  SearchResponse response = client.prepareSearch(index).setTypes(type)
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
      .setQuery(QueryBuilders.matchAllQuery())
      .setFrom(0).setSize(20).setExplain(true).execute().actionGet();
  System.out.println("length: " + response.getHits().getHits().length);
  if (response.getHits().getHits().length != 0) {
    for (SearchHit hit : response.getHits()) {
      String id = hit.getId();
      System.out.println("id: " + id);
      bulkRequest.add(client.prepareDelete(index, type, id).request());
    }
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
      for (BulkItemResponse item : bulkResponse.getItems()) {
        System.out.println(item.getFailureMessage());
      }
    } else {
      System.out.println("delete ok");
    }
  } else {
    System.out.println("delete ok");
  }
}
 
Example 5
Project: elasticsearch_my   File: RecoverAfterNodesIT.java   Source Code and License 6 votes vote down vote up
public void testRecoverAfterNodes() throws Exception {
    logger.info("--> start node (1)");
    Client clientNode1 = startNode(Settings.builder().put("gateway.recover_after_nodes", 3), 1);
    assertThat(clientNode1.admin().cluster().prepareState().setLocal(true).execute().actionGet()
            .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE),
            hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK));

    logger.info("--> start node (2)");
    Client clientNode2 = startNode(Settings.builder().put("gateway.recover_after_nodes", 3), 1);
    Thread.sleep(BLOCK_WAIT_TIMEOUT.millis());
    assertThat(clientNode1.admin().cluster().prepareState().setLocal(true).execute().actionGet()
            .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE),
            hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK));
    assertThat(clientNode2.admin().cluster().prepareState().setLocal(true).execute().actionGet()
            .getState().blocks().global(ClusterBlockLevel.METADATA_WRITE),
            hasItem(GatewayService.STATE_NOT_RECOVERED_BLOCK));

    logger.info("--> start node (3)");
    Client clientNode3 = startNode(Settings.builder().put("gateway.recover_after_nodes", 3), 1);

    assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, clientNode1).isEmpty(), equalTo(true));
    assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, clientNode2).isEmpty(), equalTo(true));
    assertThat(waitForNoBlocksOnNode(BLOCK_WAIT_TIMEOUT, clientNode3).isEmpty(), equalTo(true));
}
 
Example 6
Project: Elasticsearch   File: RestGetRepositoriesAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
            }
            builder.endObject();

            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 7
Project: Elasticsearch   File: RestIndicesExistsAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
    indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions()));
    indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
    client.admin().indices().exists(indicesExistsRequest, new RestResponseListener<IndicesExistsResponse>(channel) {
        @Override
        public RestResponse buildResponse(IndicesExistsResponse response) {
            if (response.isExists()) {
                return new BytesRestResponse(OK);
            } else {
                return new BytesRestResponse(NOT_FOUND);
            }
        }

    });
}
 
Example 8
Project: Elasticsearch   File: RestNodesHotThreadsAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    NodesHotThreadsRequest nodesHotThreadsRequest = new NodesHotThreadsRequest(nodesIds);
    nodesHotThreadsRequest.threads(request.paramAsInt("threads", nodesHotThreadsRequest.threads()));
    nodesHotThreadsRequest.ignoreIdleThreads(request.paramAsBoolean("ignore_idle_threads", nodesHotThreadsRequest.ignoreIdleThreads()));
    nodesHotThreadsRequest.type(request.param("type", nodesHotThreadsRequest.type()));
    nodesHotThreadsRequest.interval(TimeValue.parseTimeValue(request.param("interval"), nodesHotThreadsRequest.interval(), "interval"));
    nodesHotThreadsRequest.snapshots(request.paramAsInt("snapshots", nodesHotThreadsRequest.snapshots()));
    nodesHotThreadsRequest.timeout(request.param("timeout"));
    client.admin().cluster().nodesHotThreads(nodesHotThreadsRequest, new RestResponseListener<NodesHotThreadsResponse>(channel) {
        @Override
        public RestResponse buildResponse(NodesHotThreadsResponse response) throws Exception {
            StringBuilder sb = new StringBuilder();
            for (NodeHotThreads node : response) {
                sb.append("::: ").append(node.getNode().toString()).append("\n");
                Strings.spaceify(3, node.getHotThreads(), sb);
                sb.append('\n');
            }
            return new BytesRestResponse(RestStatus.OK, sb.toString());
        }
    });
}
 
Example 9
Project: elasticsearch_my   File: OpenCloseIndexIT.java   Source Code and License 6 votes vote down vote up
public void testSimpleCloseOpenAlias() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));

    IndicesAliasesResponse aliasesResponse = client.admin().indices().prepareAliases().addAlias("test1", "test1-alias").execute().actionGet();
    assertThat(aliasesResponse.isAcknowledged(), equalTo(true));

    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");

    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
 
Example 10
Project: Elasticsearch   File: RestMultiGetAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
    multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

    String[] sFields = null;
    String sField = request.param("fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), RestActions.getRestContent(request), allowExplicitIndex);

    client.multiGet(multiGetRequest, new RestToXContentListener<MultiGetResponse>(channel));
}
 
Example 11
Project: Elasticsearch   File: RestForceMergeAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
        @Override
        public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 12
Project: Elasticsearch   File: AbstractCatAction.java   Source Code and License 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    boolean helpWanted = request.paramAsBoolean("help", false);
    if (helpWanted) {
        Table table = getTableWithHeader(request);
        int[] width = buildHelpWidths(table, request);
        BytesStreamOutput bytesOutput = channel.bytesOutput();
        UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput);
        for (Table.Cell cell : table.getHeaders()) {
            // need to do left-align always, so create new cells
            pad(new Table.Cell(cell.value), width[0], request, out);
            out.append(" | ");
            pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out);
            out.append(" | ");
            pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out);
            out.append("\n");
        }
        out.close();
        channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes()));
    } else {
        doRequest(request, channel, client);
    }
}
 
Example 13
Project: ESAuthPlugin   File: ESAuthPluginAction.java   Source Code and License 5 votes vote down vote up
@Inject
public ESAuthPluginAction(Settings settings, RestController controller, Client client) {
	super(settings, controller, client);
	
	Environment environment = new Environment(settings);
    this.config = ESAuthConfig.getInstance(environment);
      
	controller.registerHandler(RestRequest.Method.GET, "/_auth/config_reload", this);
	controller.registerHandler(RestRequest.Method.GET, "/_auth/config_show", this);
}
 
Example 14
Project: elasticsearch_my   File: CircuitBreakerServiceIT.java   Source Code and License 5 votes vote down vote up
public void testBucketBreaker() throws Exception {
    if (noopBreakerUsed()) {
        logger.info("--> noop breakers used, skipping test");
        return;
    }
    assertAcked(prepareCreate("cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
    Client client = client();

    // Make request breaker limited to a small amount
    Settings resetSettings = Settings.builder()
            .put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), "100b")
            .build();
    assertAcked(client.admin().cluster().prepareUpdateSettings().setTransientSettings(resetSettings));

    // index some different terms so we have some field data for loading
    int docCount = scaledRandomIntBetween(100, 1000);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (long id = 0; id < docCount; id++) {
        reqs.add(client.prepareIndex("cb-test", "type", Long.toString(id)).setSource("test", id));
    }
    indexRandom(true, reqs);

    // A terms aggregation on the "test" field should trip the bucket circuit breaker
    try {
        SearchResponse resp = client.prepareSearch("cb-test")
                .setQuery(matchAllQuery())
                .addAggregation(terms("my_terms").field("test"))
                .get();
        assertTrue("there should be shard failures", resp.getFailedShards() > 0);
        fail("aggregation should have tripped the breaker");
    } catch (Exception e) {
        String errMsg = "CircuitBreakingException[[request] Data too large, data for [<agg [my_terms]>] would be";
        assertThat("Exception: [" + e.toString() + "] should contain a CircuitBreakingException",
                e.toString(), containsString(errMsg));
        errMsg = "which is larger than the limit of [100/100b]]";
        assertThat("Exception: [" + e.toString() + "] should contain a CircuitBreakingException",
                e.toString(), containsString(errMsg));
    }
}
 
Example 15
Project: memory-graph   File: ElasticsearchSearchMultiVertexQuery.java   Source Code and License 5 votes vote down vote up
public ElasticsearchSearchMultiVertexQuery(
        Client client,
        Graph graph,
        String[] vertexIds,
        String[] similarToFields,
        String similarToText,
        Options options,
        Authorizations authorizations
) {
    super(client, graph, similarToFields, similarToText, options, authorizations);
    hasId(vertexIds);
}
 
Example 16
Project: Elasticsearch   File: RestGetSettingsAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
    GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
            .indices(Strings.splitStringByCommaToArray(request.param("index")))
            .indicesOptions(IndicesOptions.fromRequest(request, IndicesOptions.strictExpandOpen()))
            .humanReadable(request.hasParam("human"))
            .names(names);
    getSettingsRequest.local(request.paramAsBoolean("local", getSettingsRequest.local()));

    client.admin().indices().getSettings(getSettingsRequest, new RestBuilderListener<GetSettingsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSettingsResponse getSettingsResponse, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (ObjectObjectCursor<String, Settings> cursor : getSettingsResponse.getIndexToSettings()) {
                // no settings, jump over it to shorten the response data
                if (cursor.value.getAsMap().isEmpty()) {
                    continue;
                }
                builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE);
                builder.startObject(Fields.SETTINGS);
                cursor.value.toXContent(builder, request);
                builder.endObject();
                builder.endObject();
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 17
Project: Elasticsearch   File: RestUpgradeAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestUpgradeAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(POST, "/_upgrade", this);
    controller.registerHandler(POST, "/{index}/_upgrade", this);

    controller.registerHandler(GET, "/_upgrade", this);
    controller.registerHandler(GET, "/{index}/_upgrade", this);
}
 
Example 18
Project: elasticsearch_my   File: SharedClusterSnapshotRestoreIT.java   Source Code and License 5 votes vote down vote up
public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exception {
    Client client = client();

    Path repo = randomRepoPath();
    logger.info("-->  creating repository at {}", repo.toAbsolutePath());
    assertAcked(client.admin().cluster().preparePutRepository("test-repo")
            .setType("fs").setSettings(Settings.builder()
                    .put("location", repo)
                    .put("compress", false)
                    .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));

    createIndex("test-idx-1", "test-idx-2");
    logger.info("--> indexing some data");
    indexRandom(true,
            client().prepareIndex("test-idx-1", "doc").setSource("foo", "bar"),
            client().prepareIndex("test-idx-2", "doc").setSource("foo", "bar"));

    logger.info("--> creating snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));

    logger.info("--> delete index metadata and shard metadata");
    Path indices = repo.resolve("indices");
    Path testIndex1 = indices.resolve("test-idx-1");
    Path testIndex2 = indices.resolve("test-idx-2");
    Path testIndex2Shard0 = testIndex2.resolve("0");
    IOUtils.deleteFilesIgnoringExceptions(testIndex1.resolve("snapshot-test-snap-1"));
    IOUtils.deleteFilesIgnoringExceptions(testIndex2Shard0.resolve("snapshot-test-snap-1"));

    logger.info("--> delete snapshot");
    client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();

    logger.info("--> make sure snapshot doesn't exist");
    assertThrows(client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap-1"), SnapshotMissingException.class);
}
 
Example 19
Project: Elasticsearch   File: ThreadedActionListener.java   Source Code and License 5 votes vote down vote up
public Wrapper(ESLogger logger, Settings settings, ThreadPool threadPool) {
    this.logger = logger;
    this.threadPool = threadPool;
     // Should the action listener be threaded or not by default. Action listeners are automatically threaded for client
     // nodes and transport client in order to make sure client side code is not executed on IO threads.
    this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING));
}
 
Example 20
Project: cereebro   File: ElasticSearchRelationshipDetectorTest.java   Source Code and License 5 votes vote down vote up
@Bean
public Client elasticSearchClient() {
    Client mockClient = Mockito.mock(Client.class);
    Settings settings = Settings.builder().put("cluster.name", "mycluster").build();
    Mockito.when(mockClient.settings()).thenReturn(settings);
    return mockClient;
}
 
Example 21
Project: Elasticsearch   File: RestOpenIndexAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    OpenIndexRequest openIndexRequest = new OpenIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    openIndexRequest.timeout(request.paramAsTime("timeout", openIndexRequest.timeout()));
    openIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", openIndexRequest.masterNodeTimeout()));
    openIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, openIndexRequest.indicesOptions()));
    client.admin().indices().open(openIndexRequest, new AcknowledgedRestListener<OpenIndexResponse>(channel));
}
 
Example 22
Project: Elasticsearch   File: RestNodesAction.java   Source Code and License 5 votes vote down vote up
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(true).os(true).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {
                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true).process(true).script(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
 
Example 23
Project: Elasticsearch   File: RestGetFieldMappingAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestGetFieldMappingAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(GET, "/_mapping/field/{fields}", this);
    controller.registerHandler(GET, "/_mapping/{type}/field/{fields}", this);
    controller.registerHandler(GET, "/{index}/_mapping/field/{fields}", this);
    controller.registerHandler(GET, "/{index}/{type}/_mapping/field/{fields}", this);
    controller.registerHandler(GET, "/{index}/_mapping/{type}/field/{fields}", this);
}
 
Example 24
Project: Elasticsearch   File: RestClusterSearchShardsAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterSearchShardsRequest clusterSearchShardsRequest = Requests.clusterSearchShardsRequest(indices);
    clusterSearchShardsRequest.local(request.paramAsBoolean("local", clusterSearchShardsRequest.local()));

    clusterSearchShardsRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    clusterSearchShardsRequest.routing(request.param("routing"));
    clusterSearchShardsRequest.preference(request.param("preference"));
    clusterSearchShardsRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterSearchShardsRequest.indicesOptions()));

    client.admin().cluster().searchShards(clusterSearchShardsRequest, new RestToXContentListener<ClusterSearchShardsResponse>(channel));
}
 
Example 25
Project: elasticsearch_my   File: TribeIT.java   Source Code and License 5 votes vote down vote up
private void ensureGreen(Client client) throws Exception {
    assertBusy(() -> {
        ClusterHealthResponse clusterHealthResponse = client.admin().cluster() .prepareHealth()
                .setWaitForActiveShards(0)
                .setWaitForEvents(Priority.LANGUID)
                .setWaitForNoRelocatingShards(true)
                .get();
        assertThat(clusterHealthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN));
        assertFalse(clusterHealthResponse.isTimedOut());
    });
}
 
Example 26
Project: elasticsearch-indexing-proxy   File: RequestUtils.java   Source Code and License 5 votes vote down vote up
public static DeleteRequestBuilder createDeleteRequest(final Client client, final StreamInput streamInput, final String index)
        throws IOException {
    final DeleteRequestBuilder builder = client.prepareDelete();
    final DeleteRequest request = builder.request();
    request.readFrom(streamInput);
    if (index != null) {
        request.index(index);
    }
    return builder;
}
 
Example 27
Project: Elasticsearch   File: RestTermVectorsAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestTermVectorsAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(GET, "/{index}/{type}/_termvectors", this);
    controller.registerHandler(POST, "/{index}/{type}/_termvectors", this);
    controller.registerHandler(GET, "/{index}/{type}/{id}/_termvectors", this);
    controller.registerHandler(POST, "/{index}/{type}/{id}/_termvectors", this);

    // we keep usage of _termvector as alias for now
    controller.registerHandler(GET, "/{index}/{type}/_termvector", this);
    controller.registerHandler(POST, "/{index}/{type}/_termvector", this);
    controller.registerHandler(GET, "/{index}/{type}/{id}/_termvector", this);
    controller.registerHandler(POST, "/{index}/{type}/{id}/_termvector", this);
}
 
Example 28
Project: elasticsearch_my   File: CircuitBreakerServiceIT.java   Source Code and License 5 votes vote down vote up
public void testRequestBreaker() throws Exception {
    if (noopBreakerUsed()) {
        logger.info("--> noop breakers used, skipping test");
        return;
    }
    assertAcked(prepareCreate("cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
    Client client = client();

    // Make request breaker limited to a small amount
    Settings resetSettings = Settings.builder()
            .put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), "10b")
            .build();
    assertAcked(client.admin().cluster().prepareUpdateSettings().setTransientSettings(resetSettings));

    // index some different terms so we have some field data for loading
    int docCount = scaledRandomIntBetween(300, 1000);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (long id = 0; id < docCount; id++) {
        reqs.add(client.prepareIndex("cb-test", "type", Long.toString(id)).setSource("test", id));
    }
    indexRandom(true, reqs);

    // A cardinality aggregation uses BigArrays and thus the REQUEST breaker
    try {
        client.prepareSearch("cb-test").setQuery(matchAllQuery()).addAggregation(cardinality("card").field("test")).get();
        fail("aggregation should have tripped the breaker");
    } catch (Exception e) {
        String errMsg = "CircuitBreakingException[[request] Data too large";
        assertThat("Exception: [" + e.toString() + "] should contain a CircuitBreakingException", e.toString(), containsString(errMsg));
        errMsg = "which is larger than the limit of [10/10b]]";
        assertThat("Exception: [" + e.toString() + "] should contain a CircuitBreakingException", e.toString(), containsString(errMsg));
    }
}
 
Example 29
Project: Elasticsearch   File: RestClearScrollAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestClearScrollAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);

    controller.registerHandler(DELETE, "/_search/scroll", this);
    controller.registerHandler(DELETE, "/_search/scroll/{scroll_id}", this);
}
 
Example 30
Project: Elasticsearch   File: RestDeleteWarmerAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestDeleteWarmerAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(DELETE, "/{index}/_warmer", this);
    controller.registerHandler(DELETE, "/{index}/_warmer/{name}", this);
    controller.registerHandler(DELETE, "/{index}/_warmers", this);
    controller.registerHandler(DELETE, "/{index}/_warmers/{name}", this);
}
 
Example 31
Project: Elasticsearch   File: RestAliasesExistAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestAliasesExistAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(HEAD, "/_alias/{name}", this);
    controller.registerHandler(HEAD, "/{index}/_alias/{name}", this);
    controller.registerHandler(HEAD, "/{index}/_alias", this);
}
 
Example 32
Project: Elasticsearch   File: RestIndicesAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestIndicesAction(Settings settings, RestController controller, Client client, IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, controller, client);
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    controller.registerHandler(GET, "/_cat/indices", this);
    controller.registerHandler(GET, "/_cat/indices/{index}", this);
}
 
Example 33
Project: Elasticsearch   File: RestClusterStateAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestClusterStateAction(Settings settings, RestController controller, Client client, SettingsFilter settingsFilter) {
    super(settings, controller, client);
    controller.registerHandler(RestRequest.Method.GET, "/_cluster/state", this);
    controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}", this);
    controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}/{indices}", this);

    this.settingsFilter = settingsFilter;
}
 
Example 34
Project: elasticsearch_my   File: InternalTestCluster.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a random node that applies to the given predicate.
 * The predicate can filter nodes based on the nodes settings.
 * If all nodes are filtered out this method will return <code>null</code>
 */
public synchronized Client client(final Predicate<Settings> filterPredicate) {
    ensureOpen();
    final NodeAndClient randomNodeAndClient = getRandomNodeAndClient(nodeAndClient -> filterPredicate.test(nodeAndClient.node.settings()));
    if (randomNodeAndClient != null) {
        return randomNodeAndClient.client(random);
    }
    return null;
}
 
Example 35
Project: Elasticsearch   File: RestCountAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
    countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
    if (RestActions.hasBodyContent(request)) {
        countRequest.source(RestActions.getRestContent(request));
    } else {
        QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
        if (querySourceBuilder != null) {
            countRequest.source(querySourceBuilder);
        }
    }
    countRequest.routing(request.param("routing"));
    countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
    countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    countRequest.preference(request.param("preference"));

    final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER);
    if (terminateAfter < 0) {
        throw new IllegalArgumentException("terminateAfter must be > 0");
    } else if (terminateAfter > 0) {
        countRequest.terminateAfter(terminateAfter);
    }
    client.search(countRequest.toSearchRequest(), new RestBuilderListener<SearchResponse>(channel) {
        @Override
        public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            if (terminateAfter != DEFAULT_TERMINATE_AFTER) {
                builder.field("terminated_early", response.isTerminatedEarly());
            }
            builder.field("count", response.getHits().totalHits());
            buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
                    response.getFailedShards(), response.getShardFailures());

            builder.endObject();
            return new BytesRestResponse(response.status(), builder);
        }
    });
}
 
Example 36
Project: Elasticsearch   File: RestMainAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestMainAction(Settings settings, Version version, RestController controller, ClusterName clusterName, Client client, ClusterService clusterService) {
    super(settings, controller, client);
    this.version = version;
    this.clusterName = clusterName;
    this.clusterService = clusterService;
    controller.registerHandler(GET, "/", this);
    controller.registerHandler(HEAD, "/", this);
}
 
Example 37
Project: elasticsearch_my   File: GeoShapeQueryBuilder.java   Source Code and License 5 votes vote down vote up
/**
 * Fetches the Shape with the given ID in the given type and index.
 *
 * @param getRequest
 *            GetRequest containing index, type and id
 * @param path
 *            Name or path of the field in the Shape Document where the
 *            Shape itself is located
 * @return Shape with the given ID
 * @throws IOException
 *             Can be thrown while parsing the Shape Document and extracting
 *             the Shape
 */
private ShapeBuilder fetch(Client client, GetRequest getRequest, String path) throws IOException {
    if (ShapesAvailability.JTS_AVAILABLE == false) {
        throw new IllegalStateException("JTS not available");
    }
    getRequest.preference("_local");
    getRequest.operationThreaded(false);
    GetResponse response = client.get(getRequest).actionGet();
    if (!response.isExists()) {
        throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] not found");
    }
    if (response.isSourceEmpty()) {
        throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() +
                "] source disabled");
    }

    String[] pathElements = path.split("\\.");
    int currentPathSlot = 0;

    // It is safe to use EMPTY here because this never uses namedObject
    try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, response.getSourceAsBytesRef())) {
        XContentParser.Token currentToken;
        while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (currentToken == XContentParser.Token.FIELD_NAME) {
                if (pathElements[currentPathSlot].equals(parser.currentName())) {
                    parser.nextToken();
                    if (++currentPathSlot == pathElements.length) {
                        return ShapeBuilder.parse(parser);
                    }
                } else {
                    parser.nextToken();
                    parser.skipChildren();
                }
            }
        }
        throw new IllegalStateException("Shape with name [" + getRequest.id() + "] found but missing " + path + " field");
    }
}
 
Example 38
Project: Elasticsearch   File: RestPutSearchTemplateAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestPutSearchTemplateAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, false, client);

    //controller.registerHandler(GET, "/template", this);
    controller.registerHandler(POST, "/_search/template/{id}", this);
    controller.registerHandler(PUT, "/_search/template/{id}", this);

    controller.registerHandler(PUT, "/_search/template/{id}/_create", new CreateHandler(settings, controller, client));
    controller.registerHandler(POST, "/_search/template/{id}/_create", new CreateHandler(settings, controller, client));
}
 
Example 39
Project: elasticsearch_my   File: QueryShardContext.java   Source Code and License 5 votes vote down vote up
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
        IndexFieldDataService indexFieldDataService, MapperService mapperService, SimilarityService similarityService,
        ScriptService scriptService, NamedXContentRegistry xContentRegistry,
        Client client, IndexReader reader, LongSupplier nowInMillis) {
    super(indexSettings, mapperService, scriptService, xContentRegistry, client, reader, nowInMillis);
    this.shardId = shardId;
    this.indexSettings = indexSettings;
    this.similarityService = similarityService;
    this.mapperService = mapperService;
    this.bitsetFilterCache = bitsetFilterCache;
    this.indexFieldDataService = indexFieldDataService;
    this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields();
    this.nestedScope = new NestedScope();

}
 
Example 40
Project: Elasticsearch   File: RestGetIndexTemplateAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] names = Strings.splitStringByCommaToArray(request.param("name"));

    GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
    getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
    getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));

    final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;

    client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestBuilderListener<GetIndexTemplatesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetIndexTemplatesResponse getIndexTemplatesResponse, XContentBuilder builder) throws Exception {
            boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0;

            Map<String, String> paramsMap = Maps.newHashMap();
            paramsMap.put("reduce_mappings", "true");
            ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request);

            builder.startObject();
            for (IndexTemplateMetaData indexTemplateMetaData : getIndexTemplatesResponse.getIndexTemplates()) {
                IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params);
            }
            builder.endObject();

            RestStatus restStatus = (templateExists || implicitAll) ? OK : NOT_FOUND;

            return new BytesRestResponse(restStatus, builder);
        }
    });
}
 
Example 41
Project: Elasticsearch   File: RestSearchScrollAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestSearchScrollAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);

    controller.registerHandler(GET, "/_search/scroll", this);
    controller.registerHandler(POST, "/_search/scroll", this);
    controller.registerHandler(GET, "/_search/scroll/{scroll_id}", this);
    controller.registerHandler(POST, "/_search/scroll/{scroll_id}", this);
}
 
Example 42
Project: Elasticsearch   File: RestClusterHealthAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestClusterHealthAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);

    controller.registerHandler(RestRequest.Method.GET, "/_cluster/health", this);
    controller.registerHandler(RestRequest.Method.GET, "/_cluster/health/{index}", this);
}
 
Example 43
Project: Elasticsearch   File: RestGetWarmerAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestGetWarmerAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(GET, "/_warmer/{name}", this);
    controller.registerHandler(GET, "/{index}/_warmer/{name}", this);
    controller.registerHandler(GET, "/{index}/_warmers/{name}", this);
    controller.registerHandler(GET, "/{index}/{type}/_warmer/{name}", this);
}
 
Example 44
Project: elasticsearch_my   File: TransportRolloverAction.java   Source Code and License 5 votes vote down vote up
@Inject
public TransportRolloverAction(Settings settings, TransportService transportService, ClusterService clusterService,
                               ThreadPool threadPool, MetaDataCreateIndexService createIndexService,
                               ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
                               MetaDataIndexAliasesService indexAliasesService, Client client) {
    super(settings, RolloverAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
        RolloverRequest::new);
    this.createIndexService = createIndexService;
    this.indexAliasesService = indexAliasesService;
    this.client = client;
    this.activeShardsObserver = new ActiveShardsObserver(settings, clusterService, threadPool);
}
 
Example 45
Project: elasticsearch_my   File: SharedClusterSnapshotRestoreIT.java   Source Code and License 5 votes vote down vote up
public void testDataFileFailureDuringRestore() throws Exception {
    Path repositoryLocation = randomRepoPath();
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo")
            .setType("fs").setSettings(Settings.builder().put("location", repositoryLocation)));

    prepareCreate("test-idx").setSettings(Settings.builder().put("index.allocation.max_retries", Integer.MAX_VALUE)).get();
    ensureGreen();

    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));

    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
    assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), equalTo(createSnapshotResponse.getSnapshotInfo().successfulShards()));

    logger.info("-->  update repository with mock version");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo")
            .setType("mock").setSettings(
                    Settings.builder()
                            .put("location", repositoryLocation)
                            .put("random", randomAsciiOfLength(10))
                            .put("random_data_file_io_exception_rate", 0.3)));

    // Test restore after index deletion
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> restore index after deletion");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    SearchResponse countResponse = client.prepareSearch("test-idx").setSize(0).get();
    assertThat(countResponse.getHits().getTotalHits(), equalTo(100L));
    logger.info("--> total number of simulated failures during restore: [{}]", getFailureCount("test-repo"));
}
 
Example 46
Project: gchange-pod   File: RestRegistryRecordUpdateAction.java   Source Code and License 5 votes vote down vote up
@Inject
public RestRegistryRecordUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController,
                                      RegistryService service) {
    super(settings, controller, client, securityController,
            RegistryIndexDao.INDEX, RegistryRecordDao.TYPE,
            (id, json) -> service.updateRecordFromJson(id, json));
}
 
Example 47
Project: elasticsearch_my   File: UpdateMappingOnClusterIT.java   Source Code and License 5 votes vote down vote up
private void compareMappingOnNodes(GetMappingsResponse previousMapping) {
    // make sure all nodes have same cluster state
    for (Client client : cluster().getClients()) {
        GetMappingsResponse currentMapping = client.admin().indices().prepareGetMappings(INDEX).addTypes(TYPE).setLocal(true).get();
        assertThat(previousMapping.getMappings().get(INDEX).get(TYPE).source(), equalTo(currentMapping.getMappings().get(INDEX).get(TYPE).source()));
    }
}
 
Example 48
Project: Elasticsearch   File: BulkRequestHandler.java   Source Code and License 5 votes vote down vote up
private AsyncBulkRequestHandler(Client client, BackoffPolicy backoffPolicy, BulkProcessor.Listener listener, int concurrentRequests) {
    super(client);
    this.backoffPolicy = backoffPolicy;
    assert concurrentRequests > 0;
    this.listener = listener;
    this.concurrentRequests = concurrentRequests;
    this.semaphore = new Semaphore(concurrentRequests);
}
 
Example 49
Project: Elasticsearch   File: RestClusterRerouteAction.java   Source Code and License 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    final ClusterRerouteRequest clusterRerouteRequest = Requests.clusterRerouteRequest();
    clusterRerouteRequest.dryRun(request.paramAsBoolean("dry_run", clusterRerouteRequest.dryRun()));
    clusterRerouteRequest.explain(request.paramAsBoolean("explain", clusterRerouteRequest.explain()));
    clusterRerouteRequest.timeout(request.paramAsTime("timeout", clusterRerouteRequest.timeout()));
    clusterRerouteRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterRerouteRequest.masterNodeTimeout()));
    if (request.hasContent()) {
        clusterRerouteRequest.source(request.content());
    }

    client.admin().cluster().reroute(clusterRerouteRequest, new AcknowledgedRestListener<ClusterRerouteResponse>(channel) {
        @Override
        protected void addCustomFields(XContentBuilder builder, ClusterRerouteResponse response) throws IOException {
            builder.startObject("state");
            // by default, return everything but metadata
            if (request.param("metric") == null) {
                request.params().put("metric", DEFAULT_METRICS);
            }
            settingsFilter.addFilterSettingParams(request);
            response.getState().toXContent(builder, request);
            builder.endObject();
            if (clusterRerouteRequest.explain()) {
                assert response.getExplanations() != null;
                response.getExplanations().toXContent(builder, ToXContent.EMPTY_PARAMS);
            }
        }
    });
}
 
Example 50
Project: elasticsearch_my   File: NodeClientIT.java   Source Code and License 4 votes vote down vote up
public void testThatClientTypeSettingCannotBeChanged() {
    for (Settings settings : internalCluster().getInstances(Settings.class)) {
        assertThat(Client.CLIENT_TYPE_SETTING_S.get(settings), is("node"));
    }
}
 
Example 51
Project: es-sql   File: ShowQueryAction.java   Source Code and License 4 votes vote down vote up
public ShowQueryAction(Client client, String sql) {
    super(client,null);
    this.sql = sql;
}
 
Example 52
Project: elasticsearch_my   File: BulkRequestHandler.java   Source Code and License 4 votes vote down vote up
protected BulkRequestHandler(Client client) {
    this.client = client;
    this.logger = Loggers.getLogger(getClass(), client.settings());
}
 
Example 53
Project: elasticbak   File: RestoreDataEntity.java   Source Code and License 4 votes vote down vote up
public Client getClient() {
	return client;
}
 
Example 54
Project: Elasticsearch   File: RestPutSearchTemplateAction.java   Source Code and License 4 votes vote down vote up
protected CreateHandler(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
}
 
Example 55
Project: Elasticsearch   File: RestHealthAction.java   Source Code and License 4 votes vote down vote up
@Inject
public RestHealthAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(GET, "/_cat/health", this);
}
 
Example 56
Project: Elasticsearch   File: MappingUpdatedAction.java   Source Code and License 4 votes vote down vote up
public void setClient(Client client) {
    this.client = client.admin().indices();
}
 
Example 57
Project: log4j2-elasticsearch   File: BulkProcessorObjectFactoryTest.java   Source Code and License 4 votes vote down vote up
public Client getClient() {
    return client;
}
 
Example 58
Project: memory-graph   File: ElasticsearchSearchQueryBase.java   Source Code and License 4 votes vote down vote up
public Client getClient() {
    return client;
}
 
Example 59
Project: elasticsearch_my   File: BulkRequestHandler.java   Source Code and License 4 votes vote down vote up
public static BulkRequestHandler syncHandler(Client client, BackoffPolicy backoffPolicy, BulkProcessor.Listener listener) {
    return new SyncBulkRequestHandler(client, backoffPolicy, listener);
}
 
Example 60
Project: Elasticsearch   File: RestExistsAction.java   Source Code and License 4 votes vote down vote up
public RestExistsAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
}