0

I use RestHighLevelClient to execute a query.I generate my client with multiple nodes like this.

RestHighLevelClient client = new RestHighLevelClient(
    RestClient.builder(
            new HttpHost("host1", 9200, "http"),
            new HttpHost("host2", 9200, "http"),
            new HttpHost("host2", 9200, "http")
    )

);

And do some query from several indices,But some of my index only exists in one nodes.It will cause index not found exception if i use client.search(xxx). How can i deal with this problem.

using IndicesOptions.LENIENT_EXPAND_OPEN won't throw index not found, but it seems that it just query from host1

  • can you host your code on GitHub, so that we can have a look, normally it should create a cluster and, the request goes to any node(in absence of dedicated coordinating node) and every node has cluster state, which knows which node has the data and query accordingly? – Amit Mar 25 '20 at 16:23

1 Answers1

0

I would suggest you form a ES cluster with all the 3 nodes. (Recommended) https://www.elastic.co/guide/en/elasticsearch/reference/current/add-elasticsearch-nodes.html

RestClient restClient = RestClient.builder(
        new HttpHost("host1", 9200, "http"),
        new HttpHost("host2", 9200, "http"),
        new HttpHost("host3", 9200, "http")).build();

However if you want to stick with specific host for search then you should use create separate RestHighLevelClient for each node. (Not recommended)

RestClient restClientHost1 = RestClient.builder(
        new HttpHost("host1", 9200, "http")).build();
RestClient restClientHost2 = RestClient.builder(
        new HttpHost("host2", 9200, "http")).build();
RestClient restClientHost3 = RestClient.builder(
        new HttpHost("host3", 9200, "http")).build();
Gokulraj
  • 450
  • 1
  • 3
  • 20