In the afternoon try to use Elasticsearch Java client to do data retrieval work, test the batch update, the code is as follows:
Public Static voidBulkupdategoods (list<goods> Goods)throwsIOException, Interruptedexception, executionexception {client client=NULL; Try{Client=Transportclient.builder (). Build (). Addtransportaddress (NewInetsockettransportaddress (Inetaddress.getbyname ("Hadoop-slave4"), 9300)); } Catch(Exception e) {e.printstacktrace (); } Bulkrequestbuilder req=Client.preparebulk (); for(Goods good:goods) {Req.add (Client.prepareindex ("SMMs", "goods", Good.getid () + ""). SetSource (Jsonbuilder (). StartObject (). Field ("Unit", Good.getunit ()). Field ("Price", Good.getprice ()). Field ("Name", Good.getname ()). Field ("Barcode", Good.getbarcode ()). EndObject ()); } bulkresponse Res=Req.execute (). Actionget (); if(Res.hasfailures ()) {System.out.println ("Error"); } Else{System.out.println ("Done"); } client.close (); }}
But the test always gives me this error: Nonodeavailableexception[none of the configured nodes is available. Not exactly.
Then I fix the problem after two points, one is to use 9300 port instead of 9200.9200 Port just HTTP port.
The second point is that I have cluter.name the config file in the comments and I can use it. The specific principle is not clear.
Error ElasticSearch java Client Update: Nonodeavailableexception[none of the configured nodes is available