I've created a open search service domain on AWS and i've set the property hibernate.search.backend.uris
to the address of that domain. Everything works fine, i'm able to index my entity tables and can run search queries against the open search service domain.
Yet for some reason hibernate search still routinely tries to connect to localhost:9200
in order to perform a node sniffing routine. This obviously doesn't work and the exception [es_rest_client_sniffer[T#1]] Sniffer - error while sniffing nodes java.net.ConnectException: Connection refused: no further information
is thown.
How do i stop hibernate search from performing this futile action? It keeps trying to sniff the nodes every few minutes or so. I've tried setting the fields hibernate.search.backend.hosts
and hibernate.search.backend.protocol
instead of .uris
. But even when i set those properties instead hibernate search still tries to interact with a non-existent elastic search service on localhost
. I am running hibernate search 6.1.5.Final
. The elastic search version is set to 7.16.3
. Here are all the relevant properties that i set programmatically.
jpaProperties.put("hibernate.search.backend.aws.credentials.type", "static");
jpaProperties.put("hibernate.search.backend.aws.credentials.access_key_id", awsId);
jpaProperties.put("hibernate.search.backend.aws.credentials.secret_access_key", awsKey);
jpaProperties.put("hibernate.search.backend.aws.region", openSearchAwsInstanceRegion);
jpaProperties.put("hibernate.search.backend.aws.signing.enabled", true);
//--------------------------------------------------------------------------------------------
jpaProperties.put("hibernate.search.automatic_indexing.synchronization.strategy", indexSynchronizationStrategy);
jpaProperties.put("hibernate.search.backend.request_timeout", requestTimeout);
jpaProperties.put("hibernate.search.backend.connection_timeout", elasticSearchConnectionTimeout);
jpaProperties.put("hibernate.search.backend.read_timeout", readTimeout);
jpaProperties.put("hibernate.search.backend.max_connections", maximumElasticSearchConnections);
jpaProperties.put("hibernate.search.backend.max_connections_per_route", maximumElasticSearchConnectionsPerRout);
jpaProperties.put("hibernate.search.schema_management.strategy", schemaManagementStrategy);
jpaProperties.put("hibernate.search.backend.analysis.configurer", "class:config.EnhancedLuceneAnalysisConfig");
jpaProperties.put("hibernate.search.backend.uris", elasticSearchHostAddress);
jpaProperties.put("hibernate.search.backend.directory.type", "local-filesystem");
jpaProperties.put("hibernate.search.backend.type", "elasticsearch");
jpaProperties.put("hibernate.search.backend.directory.root", luceneAbsoluteFilePath);
jpaProperties.put("hibernate.search.backend.lucene_version", "LUCENE_CURRENT");
jpaProperties.put("hibernate.search.backend.io.writer.infostream", true);
EDIT:
These are all the elastic search related dependencies that my application uses.
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch-aws</artifactId>
<version>6.1.5.Final</version>
</dependency>
Heres the stacktrace,
[ERROR] 2022-07-21 14:33:58.402 [es_rest_client_sniffer[T#1]] Sniffer - error while sniffing nodes
java.net.ConnectException: Connection refused: no further information
at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:918) ~[elasticsearch-rest-client-7.17.3.jar:7.17.3]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:299) ~[elasticsearch-rest-client-7.17.3.jar:7.17.3]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:287) ~[elasticsearch-rest-client-7.17.3.jar:7.17.3]
at org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.sniff(ElasticsearchNodesSniffer.java:106) ~[elasticsearch-rest-client-sniffer-7.17.3.jar:7.17.3]
at org.elasticsearch.client.sniff.Sniffer.sniff(Sniffer.java:209) ~[elasticsearch-rest-client-sniffer-7.17.3.jar:7.17.3]
at org.elasticsearch.client.sniff.Sniffer$Task.run(Sniffer.java:140) ~[elasticsearch-rest-client-sniffer-7.17.3.jar:7.17.3]
at org.elasticsearch.client.sniff.Sniffer$1.run(Sniffer.java:81) ~[elasticsearch-rest-client-sniffer-7.17.3.jar:7.17.3]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.Net.pollConnect(Native Method) ~[?:?]
at sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[?:?]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946) ~[?:?]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174) ~[httpcore-nio-4.4.15.jar:4.4.15]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148) ~[httpcore-nio-4.4.15.jar:4.4.15]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351) ~[httpcore-nio-4.4.15.jar:4.4.15]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.5.jar:4.1.5]
... 1 more
This stacktrace was copied after i had removed <elasticsearch.version>7.16.3</elasticsearch.version>
so see whether that would solve the problem. If the version is missing hibernate search seems to default to version 7.17.3
CodePudding user response:
Hibernate Search will only enable node discovery (create a sniffer) if the configuration property hibernate.search.backend.discovery.enabled
is set to true
, and by default it's false
.
If the properties you listed are the only ones you set, then I don't think Hibernate Search is creating this sniffer. The sniffer also doesn't use the URIs you passed to Hibernate Search, so that as well tends to prove the sniffer is not created by Hibernate Search.
If you don't believe me, see by yourself by starting your app in debug mode and putting a breakpoint in org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientFactoryImpl#createSniffer
.
I think you probably have something else in your application creating an Elasticsearch client and a sniffer, and that something else is not completely configured. Try launching your application in debug mode and putting breakpoints in the constructors of org.elasticsearch.client.sniff.Sniffer
?
CodePudding user response:
It took a while but i finally found the source of the problem.
Apparently spring boot
has a built-in autoconfiguration class for Elastic search
called ElasticsearchRestClientAutoConfiguration
. The code in this class is run by default and it initializes a org.elasticsearch.client.RestClient
that that has a node sniffer
enabled by default. If no elastic search server is running on localhost this RestClient
will keep throwing exceptions because there is nothing to connect to.
Because this class is not part of the hibernate search
java library settings such as hibernate.search.backend.discovery.enabled = false
do not influence this RestClient
or its Sniffer
.
You can prevent Spring
from creating this RestClient
by telling Spring
not to run ElasticsearchRestClientAutoConfiguration
. This can be done in two ways.
Firstly you can add the following property to your application.properties
:
spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration
Second, you can also exclude this autoconfiguration class by adding it as a value to the exclude
argument of the add this @SpringBootApplication
annotation. For instance:
@SpringBootApplication(exclude ={ElasticsearchRestClientAutoConfiguration.class})
public class MyConfiguration {