Worried about app after moving to 6.6.1

Since moving to 6.6.1 REST client, I noticed my client connection is not closing.
So I am using a System.exit(0) at the method end.
FYI: The document is getting stored and update din Elastic!

This is how I get my client/authenticate:

String CREDENTIALS_STRING = this.username+":"+this.password;
		String encodedBytes = Base64.getEncoder().encodeToString(CREDENTIALS_STRING.getBytes());
		Header[] headers = { new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"),
				new BasicHeader("Authorization", "Basic " + encodedBytes) };
		this.client = new RestHighLevelClient(RestClient.builder(
		        new HttpHost(this.END_POINT, 9243, "https")).setDefaultHeaders(headers));
		return this.client;

This is how I used to do it:

String CREDENTIALS_STRING = this.username+":"+this.password;
		String encodedBytes = Base64.getEncoder().encodeToString(CREDENTIALS_STRING.getBytes());
		Header[] headers = { new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"),
				new BasicHeader("Authorization", "Basic " + encodedBytes) };
		this.restLowLevelClient = RestClient.builder(
		        new HttpHost(this.END_POINT, 9243, "https")).setDefaultHeaders(headers).build();
		this.client = new RestHighLevelClient(restLowLevelClient);
		
		return this.client;

At the end of the request, I am attempting to evaluate the response. I am getting "NOOP" when I check the UpdateResponse, what does that mean?:

IndexRequest indexRequest = new IndexRequest(indexName, docType,
					String.valueOf(fieldMap.get(updateIdField))).source(fieldMap);

			UpdateRequest upR = new UpdateRequest(indexName, docType, String.valueOf(fieldMap.get(updateIdField)))
					.doc(indexRequest).upsert(indexRequest);

			UpdateResponse updateResponse = null;
			try {
				updateResponse = client.update(upR, RequestOptions.DEFAULT);
				
				System.out.println(updateResponse.getResult());
				//here it's printing "NOOP"
				
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}

Also, when I send the request, I use RequestOptions.DEFAULT. does this interfere with my Headers that I set initially when getting the client? I feel like I may be undoing the client when I follow up using DEFAULT RequestOptions?? :

updateResponse = client.update(upR, RequestOptions.DEFAULT);

Not sure I understood the problem.
Did you call client.close(); ?

calling client.close() is not working.
My eclipse is still running, unless I use System.exit(0);

Could you share a full project that reproduces your problem?

It can be super simple like:

public class App {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(HttpHost.create("http://localhost:9200")));
        
        try {
             client.indices().delete(new DeleteIndexRequest("test"), RequestOptions.DEFAULT);
            for (int i = 0; i < 100; i++) {
                client.index(new IndexRequest("test", "_doc").source("foo", "bar"), RequestOptions.DEFAULT);
            }
            client.indices().refresh(new RefreshRequest("test"), RequestOptions.DEFAULT);

            SearchRequest searchRequest = new SearchRequest("test");
            SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

            System.out.println("response size = " + searchResponse.getHits().getHits().length);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            client.close();
        }
    }
}

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