Java 类org.elasticsearch.client.Client 实例源码

项目:elasticsearch_my    文件:BlobStoreRepositoryTests.java   
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;
}
项目:Elasticsearch    文件:RestFlushAction.java   
@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);
        }
    });
}
项目:elasticsearch_my    文件:TribeUnitTests.java   
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")));
                }
            });
        }
    }
}
项目:elasticsearch_my    文件:RecoverAfterNodesIT.java   
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));
}
项目:Elasticsearch    文件:RestGetRepositoriesAction.java   
@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);
        }
    });
}
项目:Elasticsearch    文件:RestIndicesExistsAction.java   
@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);
            }
        }

    });
}
项目:Elasticsearch    文件:RestNodesHotThreadsAction.java   
@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());
        }
    });
}
项目:elasticsearch_my    文件:OpenCloseIndexIT.java   
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");
}
项目:elasticsearch    文件:App.java   
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");
  }
}
项目:Elasticsearch    文件:RestMultiGetAction.java   
@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));
}
项目:Elasticsearch    文件:RestForceMergeAction.java   
@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);
        }
    });
}
项目:Elasticsearch    文件:AbstractCatAction.java   
@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);
    }
}
项目:ESAuthPlugin    文件:ESAuthPluginAction.java   
@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);
}
项目:elasticsearch_my    文件:CircuitBreakerServiceIT.java   
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));
    }
}
项目:memory-graph    文件:ElasticsearchSearchMultiVertexQuery.java   
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);
}
项目:Elasticsearch    文件:RestGetSettingsAction.java   
@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);
        }
    });
}
项目:Elasticsearch    文件:RestUpgradeAction.java   
@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);
}
项目:elasticsearch_my    文件:SharedClusterSnapshotRestoreIT.java   
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);
}
项目:Elasticsearch    文件:ThreadedActionListener.java   
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));
}
项目:cereebro    文件:ElasticSearchRelationshipDetectorTest.java   
@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;
}
项目:Elasticsearch    文件:RestOpenIndexAction.java   
@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));
}
项目:Elasticsearch    文件:RestNodesAction.java   
@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);
                        }
                    });
                }
            });
        }
    });
}
项目:Elasticsearch    文件:RestGetFieldMappingAction.java   
@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);
}
项目:Elasticsearch    文件:RestClusterSearchShardsAction.java   
@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));
}
项目:elasticsearch_my    文件:TribeIT.java   
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());
    });
}
项目:elasticsearch-indexing-proxy    文件:RequestUtils.java   
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;
}
项目:Elasticsearch    文件:RestTermVectorsAction.java   
@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);
}
项目:elasticsearch_my    文件:CircuitBreakerServiceIT.java   
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));
    }
}
项目:Elasticsearch    文件:RestClearScrollAction.java   
@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);
}
项目:Elasticsearch    文件:RestDeleteWarmerAction.java   
@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);
}
项目:Elasticsearch    文件:RestAliasesExistAction.java   
@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);
}
项目:Elasticsearch    文件:RestIndicesAction.java   
@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);
}
项目:Elasticsearch    文件:RestClusterStateAction.java   
@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;
}
项目:elasticsearch_my    文件:InternalTestCluster.java   
/**
 * 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;
}
项目:Elasticsearch    文件:RestCountAction.java   
@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);
        }
    });
}
项目:Elasticsearch    文件:RestMainAction.java   
@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);
}
项目:elasticsearch_my    文件:GeoShapeQueryBuilder.java   
/**
 * 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");
    }
}
项目:Elasticsearch    文件:RestPutSearchTemplateAction.java   
@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));
}
项目:elasticsearch_my    文件:QueryShardContext.java   
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();

}
项目:Elasticsearch    文件:RestGetIndexTemplateAction.java   
@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);
        }
    });
}