Java REST Client and Multithreading


Is the Java REST Client Thread safe?

Can I instantiate a single client object and share among the threads?
Or should I open separate connections in each thread?

Problem with Bulk API instantiation
(David Pilato) #2

One client only is fine IMO.


7000 records are taking forever to reach Elastic :disappointed_relieved:

(David Pilato) #4

But what are you doing?

Calling index() 7000 times? If so, that's not the best solution here.
But please be more specific about what your problem is.


I'm looping, the reason is, the AWS instance I was using kept running out of memory while uploading to Hubspot. Keeping the objects in memory was the problem, and very little RAM.

So I decided to serialize the objects then send to Elastic. This is why I didn't use the BULK API in the first place.

I've since increased the RAM from 2 GB to 8GB, so maybe I can revisit the BULK API.

public static void insertCDSData(HubspotContact registrant) {
	CDSRegImport_ES_Credentials credentials = new CDSRegImport_ES_Credentials();
	RestHighLevelClient client = credentials.getClient();
		IndexRequest indexRequest = new IndexRequest("cdsregimport", "CDSREGIMPORT", registrant.getBadge()).
						"lastname", registrant.getLastName(),
						"ATS ID",registrant.getATSID(),
						"Address 1",registrant.getMailStreet1(),
						"Address 2", registrant.getMailStreet2(),
						"Country", registrant.getMailCountry(),
						"Registration Type", registrant.getRegistrationType(),
						"Title", registrant.getTitle(),
						"Topics of Interest",registrant.getTopicOfInterest(),
						"CDS Address Type",registrant.getAddressType(),
						"Work Settings", registrant.getWorkSettings(),
						"Nature of Professional Activities", registrant.getNatureOfProfessionalWork(),
						"postDate", new Date());
		UpdateRequest upR = new UpdateRequest("cdsregimport", "CDSREGIMPORT", String.valueOf(registrant.getBadge())).doc(indexRequest)
		UpdateResponse updateResponse = null;
			updateResponse = client.update(upR);
		}catch(IOException ioe){
		upR = null;
		registrant = null;
		indexRequest = null;


(David Pilato) #6

Definitely the bulk processor will help you here.

BTW did you look at It runs also on AWS.


AWS is way too expensive for ES.
Other services, yes, ES, no.

(system) #9

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.