1

I am new to JEST technology. I am practicing it from https://github.com/searchbox-io/Jest/tree/master/jest#authentication link. I am able to create index and adding documents to it, but I want to to pass multiple nodes.

Here is my code

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();

I am having 3 node cluster, so I want to pass 3 nodes in code. Any help will be appreciated.

Thank you

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Ash
  • 149
  • 1
  • 1
  • 13

1 Answers1

1

Actually, as written in the link you gave, you can pass to the Builder a list, see:

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()
);

Actually to be more precise, the Builder accepts a Collection<String>, see: https://github.com/searchbox-io/Jest/blob/master/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java#L127

Adonis
  • 4,670
  • 3
  • 37
  • 57
  • Hi @asettouf..Thank you for your time. I tried the above code but it seems that it works only if all three nodes are up and running. If one node fails(I did that manually) the code shows error `Exception in thread "main" io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://192.169.1.2:9200`. I want to cover that scenario as well.What could be the possible solution for it. – Ash Jul 15 '17 at 12:41
  • @Ash Have you tried using the node discovery? https://github.com/searchbox-io/Jest/tree/master/jest#node-discovery-through-nodes-api – Adonis Jul 15 '17 at 13:05
  • I tried this,but it is giving same error. `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");` – Ash Jul 15 '17 at 13:30
  • Actullay , there is Exception but new index is created with exception, but I can not insert values into that..The code I am trying is `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 Jul 15 '17 at 13:55
  • @Ash From what I've seen so far, either you have a master node you can poll for discovery, or you have to manage the discovery inside your own program. – Adonis Jul 16 '17 at 14:51