Search in sources :

Example 11 with ClusterSearchShardsResponse

use of org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse in project elasticsearch by elastic.

the class ClusterSearchShardsIT method testMultipleShardsSingleNodeAllocation.

public void testMultipleShardsSingleNodeAllocation() throws Exception {
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", "4").put("index.number_of_replicas", 0).put("index.routing.allocation.include.tag", "A")).execute().actionGet();
    ensureGreen();
    ClusterSearchShardsResponse response = client().admin().cluster().prepareSearchShards("test").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(4));
    assertThat(response.getGroups()[0].getShardId().getIndexName(), equalTo("test"));
    assertThat(response.getNodes().length, equalTo(1));
    assertThat(response.getGroups()[0].getShards()[0].currentNodeId(), equalTo(response.getNodes()[0].getId()));
    response = client().admin().cluster().prepareSearchShards("test").setRouting("ABC").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(1));
    response = client().admin().cluster().prepareSearchShards("test").setPreference("_shards:2").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(1));
    assertThat(response.getGroups()[0].getShardId().getId(), equalTo(2));
}
Also used : ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse)

Aggregations

ClusterSearchShardsResponse (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse)11 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ClusterSearchShardsGroup (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup)4 UnknownHostException (java.net.UnknownHostException)3 List (java.util.List)3 Map (java.util.Map)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TransportException (org.elasticsearch.transport.TransportException)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 Collectors (java.util.stream.Collectors)2 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)2 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)2 CountDown (org.elasticsearch.common.util.concurrent.CountDown)2