Search in sources :

Example 66 with Client

use of org.elasticsearch.client.Client in project sonarqube by SonarSource.

the class IndexerStartupTask method closeIndex.

private void closeIndex(String index) {
    Client nativeClient = esClient.nativeClient();
    CloseIndexAction.INSTANCE.newRequestBuilder(nativeClient).setIndices(index).get();
}
Also used : Client(org.elasticsearch.client.Client)

Example 67 with Client

use of org.elasticsearch.client.Client in project sonarqube by SonarSource.

the class IndexerStartupTask method waitForIndexYellow.

private void waitForIndexYellow(String index) {
    Client nativeClient = esClient.nativeClient();
    ClusterHealthAction.INSTANCE.newRequestBuilder(nativeClient).setIndices(index).setWaitForYellowStatus().get(TimeValue.timeValueMinutes(10));
}
Also used : Client(org.elasticsearch.client.Client)

Example 68 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class SearchPreferenceIT method testNodesOnlyRandom.

public void testNodesOnlyRandom() throws Exception {
    assertAcked(prepareCreate("test").setSettings(//this test needs at least a replica to make sure two consecutive searches go to two different copies of the same data
    Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(1, maximumNumberOfReplicas()))));
    ensureGreen();
    client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet();
    refresh();
    final Client client = internalCluster().smartClient();
    SearchRequestBuilder request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(// multiple wildchar  to cover multi-param usecase
    "_only_nodes:*,nodes*");
    assertSearchOnRandomNodes(request);
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference("_only_nodes:*");
    assertSearchOnRandomNodes(request);
    ArrayList<String> allNodeIds = new ArrayList<>();
    ArrayList<String> allNodeNames = new ArrayList<>();
    ArrayList<String> allNodeHosts = new ArrayList<>();
    NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().execute().actionGet();
    for (NodeStats node : nodeStats.getNodes()) {
        allNodeIds.add(node.getNode().getId());
        allNodeNames.add(node.getNode().getName());
        allNodeHosts.add(node.getHostname());
    }
    String node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeIds.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeNames.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeHosts.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    node_expr = "_only_nodes:" + Strings.arrayToCommaDelimitedString(allNodeHosts.toArray());
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
    // Mix of valid and invalid nodes
    node_expr = "_only_nodes:*,invalidnode";
    request = client.prepareSearch("test").setQuery(matchAllQuery()).setPreference(node_expr);
    assertSearchOnRandomNodes(request);
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ArrayList(java.util.ArrayList) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Client(org.elasticsearch.client.Client)

Example 69 with Client

use of org.elasticsearch.client.Client in project elasticsearch by elastic.

the class SearchPreferenceIT method testNoPreferenceRandom.

public void testNoPreferenceRandom() throws Exception {
    assertAcked(prepareCreate("test").setSettings(//this test needs at least a replica to make sure two consecutive searches go to two different copies of the same data
    Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(1, maximumNumberOfReplicas()))));
    ensureGreen();
    client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet();
    refresh();
    final Client client = internalCluster().smartClient();
    SearchResponse searchResponse = client.prepareSearch("test").setQuery(matchAllQuery()).execute().actionGet();
    String firstNodeId = searchResponse.getHits().getAt(0).getShard().getNodeId();
    searchResponse = client.prepareSearch("test").setQuery(matchAllQuery()).execute().actionGet();
    String secondNodeId = searchResponse.getHits().getAt(0).getShard().getNodeId();
    assertThat(firstNodeId, not(equalTo(secondNodeId)));
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Client(org.elasticsearch.client.Client) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 70 with Client

use of org.elasticsearch.client.Client in project spring-boot by spring-projects.

the class ElasticsearchAutoConfigurationTests method createNodeClientWithOverrides.

@Test
public void createNodeClientWithOverrides() {
    this.context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "spring.data.elasticsearch.properties.foo.bar:baz", "spring.data.elasticsearch.properties.path.home:target", "spring.data.elasticsearch.properties.node.local:false", "spring.data.elasticsearch.properties.node.data:true", "spring.data.elasticsearch.properties.http.enabled:true");
    this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(Client.class).length).isEqualTo(1);
    NodeClient client = (NodeClient) this.context.getBean(Client.class);
    assertThat(client.settings().get("foo.bar")).isEqualTo("baz");
    assertThat(client.settings().get("node.local")).isEqualTo("false");
    assertThat(client.settings().get("node.data")).isEqualTo("true");
    assertThat(client.settings().get("http.enabled")).isEqualTo("true");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) NodeClient(org.elasticsearch.client.node.NodeClient) Client(org.elasticsearch.client.Client) NodeClient(org.elasticsearch.client.node.NodeClient) Test(org.junit.Test)

Aggregations

Client (org.elasticsearch.client.Client)164 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)42 Settings (org.elasticsearch.common.settings.Settings)38 Path (java.nio.file.Path)30 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)28 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)24 ArrayList (java.util.ArrayList)23 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)23 IOException (java.io.IOException)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)18 ClusterState (org.elasticsearch.cluster.ClusterState)17 ExecutionException (java.util.concurrent.ExecutionException)16 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)13 ClusterService (org.elasticsearch.cluster.service.ClusterService)10 List (java.util.List)9 ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)9 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9