Home > OS >  How To Remove Warning Messages From RestHighLevelClient
How To Remove Warning Messages From RestHighLevelClient

Time:08-18

I am getting the below Warning messages for every query that is sent from the Spring Boot API and would like to remove it from the Logs.

2022-08-17 12:41:31.123  WARN 61390 --- [nio-9002-exec-2] org.elasticsearch.client.RestClient      : request [POST http://localhost:9200/_search?typed_keys=true&max_concurrent_shard_requests=5&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512&ccs_minimize_roundtrips=true] returned 1 warnings: [299 Elasticsearch-7.14.1-66b55ebfa59c92c15 "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-minimal-setup.html to enable security."]

I am using the RestHighLevelClient. According to Elasticsearch, this can be solved by migrating to The Elasticsearch Java API Client that they recently introduced. However, this would take a long time for us make that kind of change.

The Elasticsearch version is 7.14.1 and unfortunately, we can not upgrade this.

I was wondering if there is a simpler solution to this problem.

CodePudding user response:

This warning are coming because you have not enable security for elasticsearch cluster and anyone can access your elasticsearch cluster using URL. You can enable basic authentication to your elasticsearch cluster to remove this warning.

Please check this documentation for how to enable security for your elasticsearch cluster.

Also, once you enable security, you can use below code to pass authentication details to Java High Level client for connecting to secure elasticsearch cluster.

RestClientBuilder builder = RestClient.builder(new HttpHost(hostname, port));

CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(elasticUserName, password));

builder.setHttpClientConfigCallback(httpClientBuilder -> {
                httpClientBuilder.disableAuthCaching();
                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            });

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);

CodePudding user response:

I solved the issue simply by adding the options to the .properties for the Logback as below;

logging.level.root=ERROR
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

Thanks for the top answer on this post.

  • Related