How to balance the Elastic search nodes using TransportClient java code

gurdeep.sabarwal

looking for expert's help(i am newbie on elastic search)... have multiple nodes of elastic search.

i am using ElasticSearch java lib for indexing the json docs. would like to know how to handle the node balancing,is it possible to handle that from client side?

---elasticSearch transport client code------

public static Client getTransportClient(String host, int port) {
     Settings settings = ImmutableSettings.settingsBuilder()
                                              .put("cluster.name", "ccw_cat_es")
                                              .put("node.name", "catsrch-pdv1-01")
                                              .build();
      return new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(host, port));
   }
   public static IndexResponse doIndex(Client client, String index, String type, String id, Map<String, Object> data) {
       return client
                    .prepareIndex(index, type, id)
                    .setSource(data)
                    .execute()
                    .actionGet();
   }
    public static void main(String[] args) {
        Client client = getTransportClient("catsrch-pdv1-01", 9200);
        String index  = "orderstatussearch";
        String type   = "osapi";
        String id     = null;       
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("OrderNumber", "444");
        data.put("PO", "123");
        data.put("WID", "ab234");

        id= "444";
        IndexResponse result = doIndex(client, index, type, id, data);
    }

pickypg

The TransportClient will automatically use a round robin strategy to load balance against nodes that it is connected too. In your case, you are only connecting to one node, so there is nothing to balance. You can add other nodes to the list and it will balance them appropriately.

Alternatively, you can "sniff" out the data nodes automatically by just connecting to one of them with an extra setting applied:

Settings settings = ImmutableSettings.settingsBuilder()
    // ...
    .put("client.transport.sniff", true)
    // ...
    .build()

This will then round robin against all data nodes that it finds in the cluster state.

This probably leads to the question: why isn't this the default? The reason is that, if you have standalone client nodes, then they are better proxies to the cluster rather than directly communicating with data nodes. For smaller clusters, this is a perfectly acceptable strategy though.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to balance the Elastic search nodes using TransportClient java code

From Dev

Elastic Search TransportClient

From Dev

How to write json mapping in java using elastic search RestHighLevelClient?

From Dev

AND Query using Elastic Search Java API

From Dev

How to generate elastic search nested aggregations in java?

From Dev

how to translate nested elastic search query in java?

From Dev

Can I search by multiple fields using the Elastic Search Java API?

From Dev

How Should i calculate the balance Using R code

From Dev

How can I set a parent / child relationship using the Elastic Search Java API?

From Dev

How to make a search engine using elastic search and javascript and HTML

From Dev

Migrating elastic search from 1.4.3 to 2.4 java code

From Dev

How to load balance jobs using spring batch when different nodes has different times?

From Dev

How to load balance jobs using spring batch when different nodes has different times?

From Dev

get FXML file nodes using java code

From Dev

get FXML file nodes using java code

From Dev

Elastic Search URI /_cluster/nodes not accessible

From Dev

Elastic Search using NEST

From Dev

create an index template using the java api in elastic search

From Dev

create an index template using the java api in elastic search

From Dev

Retrieving json data of elastic search using ajax and java script

From Dev

How to I have Elastic Search (with multiple nodes) and Kibana in one docker compose file?

From Dev

How to filter last 5 minutes, date histogram using Elastic search?

From Dev

how to do an atomic increment using elastic search update?

From Dev

How to interact with elastic search Alias using Spring data

From Java

How to retrieve unique count of a field using Kibana + Elastic Search

From Dev

How to update child document in Elastic search using update API?

From Dev

how to return all fields when using scripted fields in elastic search

From Dev

How to Index Array of String using NEST(1.8) in Elastic Search?

From Dev

How to Index Json Data using NEST Client for Elastic Search?

Related Related

  1. 1

    How to balance the Elastic search nodes using TransportClient java code

  2. 2

    Elastic Search TransportClient

  3. 3

    How to write json mapping in java using elastic search RestHighLevelClient?

  4. 4

    AND Query using Elastic Search Java API

  5. 5

    How to generate elastic search nested aggregations in java?

  6. 6

    how to translate nested elastic search query in java?

  7. 7

    Can I search by multiple fields using the Elastic Search Java API?

  8. 8

    How Should i calculate the balance Using R code

  9. 9

    How can I set a parent / child relationship using the Elastic Search Java API?

  10. 10

    How to make a search engine using elastic search and javascript and HTML

  11. 11

    Migrating elastic search from 1.4.3 to 2.4 java code

  12. 12

    How to load balance jobs using spring batch when different nodes has different times?

  13. 13

    How to load balance jobs using spring batch when different nodes has different times?

  14. 14

    get FXML file nodes using java code

  15. 15

    get FXML file nodes using java code

  16. 16

    Elastic Search URI /_cluster/nodes not accessible

  17. 17

    Elastic Search using NEST

  18. 18

    create an index template using the java api in elastic search

  19. 19

    create an index template using the java api in elastic search

  20. 20

    Retrieving json data of elastic search using ajax and java script

  21. 21

    How to I have Elastic Search (with multiple nodes) and Kibana in one docker compose file?

  22. 22

    How to filter last 5 minutes, date histogram using Elastic search?

  23. 23

    how to do an atomic increment using elastic search update?

  24. 24

    How to interact with elastic search Alias using Spring data

  25. 25

    How to retrieve unique count of a field using Kibana + Elastic Search

  26. 26

    How to update child document in Elastic search using update API?

  27. 27

    how to return all fields when using scripted fields in elastic search

  28. 28

    How to Index Array of String using NEST(1.8) in Elastic Search?

  29. 29

    How to Index Json Data using NEST Client for Elastic Search?

HotTag

Archive