【问题标题】:How to pass multiple node's address in jest (Elastic Search)如何开玩笑地传递多个节点地址(Elasticsearch)
【发布时间】:2017-12-20 05:47:27
【问题描述】:

我是 JEST 技术的新手。我正在通过https://github.com/searchbox-io/Jest/tree/master/jest#authentication 链接练习它。我能够创建索引并向其添加文档,但我想传递多个节点。

这是我的代码

JestClientFactory factory = new JestClientFactory();

factory.setHttpClientConfig(new HttpClientConfig 
        .Builder("http://192.167.1.2:9200") 
        .defaultCredentials("user", "password")
        .multiThreaded(false) 
        //Per default this implementation will create no more than 2 concurrent connections per given route 
        .defaultMaxTotalConnectionPerRoute(2) // and no more 20 connections in total 
        .maxTotalConnection(5) 
        .build());

JestClient client = factory.getObject();

我有 3 个节点的集群,所以我想在代码中传递 3 个节点。任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: elasticsearch elasticsearch-jest


    【解决方案1】:

    其实就像link you gave里写的,可以给Builder传一个list,见:

    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(
        new HttpClientConfig.Builder(Arrays.asList("http://192.168.0.88:9200", "http://192.168.0.172:9200"))
            .credentialsProvider(customCredentialsProvider)
            .build()
    );
    

    实际上更准确地说,Builder 接受Collection<String>,见:https://github.com/searchbox-io/Jest/blob/master/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java#L127

    【讨论】:

    • 嗨@asettouf ..谢谢你的时间。我尝试了上面的代码,但它似乎只有在所有三个节点都启动并运行时才有效。如果一个节点发生故障(我手动完成),代码将显示错误Exception in thread "main" io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://192.169.1.2:9200。我也想介绍这种情况。可能的解决方案是什么。
    • @Ash 你试过使用节点发现吗? github.com/searchbox-io/Jest/tree/master/…
    • 我试过这个,但它给出了同样的错误。 ClientConfig clientConfig = new ClientConfig.Builder(Arrays.asList("http://192.169.1.2:9200","192.169.1.3:9200","192.169.1.4:9200")) .discoveryEnabled(true) .discoveryFrequency(1l, TimeUnit.MINUTES) .discoveryFilter("type:arbitrary") .build(); System.out.println("connected");
    • Actullay ,有异常,但新索引是用异常创建的,但我不能在其中插入值..我正在尝试的代码是PutMapping putMapping = new PutMapping.Builder( "javatest13", "javatesttype13", "{ \"javatesttype13\" : { \"properties\" : { \"name\" : {\"type\" : \"text\", \"store\" : \"yes\", \"index\" : \"true\" } }}}; " ).build(); client.execute(putMapping); String source="{\"name\":\"kim123\",\"id\":\"12345\",\"address\":\"Newyork3\"}";
    • @Ash 从我目前看到的情况来看,要么你有一个可以轮询发现的主节点,要么你必须在自己的程序中管理发现。
    猜你喜欢
    • 1970-01-01
    • 2021-06-20
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 2021-05-27
    • 2018-11-19
    • 2022-01-24
    相关资源
    最近更新 更多