Several question about SSL/TLS

Hi, I am reference security configured SSL/TLS in elasticsearch

My elasticsearch.yml: true MY_IP true certificate certs/elastic-certificates.p12 certs/elastic-certificates.p12 true certs/elastic-certificates.p12 certs/elastic-certificates.p12

when curl -k -u elastic:123456 -X GET https://MY_IP:9200,there is nothing wrong.

My question:

1. How can I  get the same result without "-k" 
2. How to connect with elasticsearch in java 

Hope for answer,Thanks!


in order to not use curl -k you would need to make sure that curl knows the cacert you used to create the Elasticsearch certificates.

Regarding your second question and java. The client connecting to elasticsearch also needs to know about the CA you used to sign the certificates. See


@spinscale ,Thank you for your replay.
but really I don't know is how can I generate CA,or the CA means elastic-stack-ca.p12?
can you please show me a sample or some blogs.
thanks again.

I assume that somehow you generated those certificates? Or did you get that from a third party? Regardless you have to add those to the programs you execute in order to prevent those warning messages (be it curl or the java client).

Did you follow the documentation or how were those created?

@spinscale Thank you for your replay.

Firstly , I use x-pack complete basic auth.

Secondly,I execute bin/elasticsearch-certutil ca then elastic-stack-ca.p12 was generated with no password protected.

Thirdly, I execute bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 then elastic-certificates.p12 was generated with no password protected.

Fourthly, I move elastic-stack-ca.p12 and elastic-certificates.p12 to config/certs and restart.

At last, I executecurl -k -u elastic:123456 -X GET https://MY_IP:9200 , and Elasticsearch show me a json.

My elasticsearch.yml was configured as mentioned above.

So, at this case, how can I generate certificates and connect with elasticsearch in java

sorry that I have so many question and waste your time
Hope for your answer,thank you again.

@spinscale I am very happy to tell that I have resolved this problem. The "CA" you have mentioned" is elastic-certificates.p12 that I already generated. My java client is as below.
hope this can help someone who need.

public static boolean auth(String index) throws Exception {
	CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "123456"));
	KeyStore truststore = KeyStore.getInstance("jks");
	try (InputStream is = new FileInputStream("./src/main/resources/elastic-certificates.p12")) {
		truststore.load(is, "123456".toCharArray());
	SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
	final SSLContext sslContext =;
	RestClientBuilder builder = RestClient.builder(new HttpHost("MY_IP", 9200, "https"))
			.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
				public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
					return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)

	client = new RestHighLevelClient(builder);
	GetIndexRequest req = new GetIndexRequest(index);
	return client.indices().exists(req, RequestOptions.DEFAULT);

my elasticsearch.yml is as below: true MY_IP true certificate certs/elastic-certificates.p12 certs/elastic-certificates.p12 true certs/elastic-certificates.p12 certs/elastic-certificates.p12 123456 123456 123456 123456

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