0

我使用 RestHighLevelClient 来执行查询。我用这样的多个节点生成我的客户端。

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

);

并从多个索引中查询,但我的一些索引只存在于一个节点中。如果我使用 client.search(xxx) 会导致 index not found 异常。我该如何处理这个问题。

使用 IndicesOptions.LENIENT_EXPAND_OPEN 不会抛出未找到索引,但它似乎只是从 host1 查询

4

1 回答 1

0

我建议你用所有 3 个节点组成一个 ES 集群。(推荐) 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();

但是,如果您想坚持使用特定主机进行搜索,那么您应该为每个节点创建单独的 RestHighLevelClient。(不建议)

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();
于 2020-03-25T08:12:37.700 回答