Home > database >  Elasticsearch stops working after I run the springboot Java program and elasticsearch transport node
Elasticsearch stops working after I run the springboot Java program and elasticsearch transport node

Time:04-27

Elasticsearch version 8.1.3 Java version 1.8

Im trying to connect elasticsearch with Java springboot program. My Elasticsearch works fine until I run the Java program, also my java program works fine but with ".d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{LsJSQJtCS56wr7IM_S0h4Q}{localhost}{127.0.0.1:9300}]" on springboot error. Also, as soon as I run my program as java application elasticsearch stops working with "[WARN ][o.e.x.c.s.t.n.SecurityNetty4Transport] [DESKTOP-ADQ0I0S] received plaintext traffic on an encrypted channel, closing connection Netty4TcpChannel{localAddress=/127.0.0.1:9300, remoteAddress=/127.0.0.1:59255, profile=default}"

My pom.xml file

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>

4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.elasticsearch</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-elasticsearch-example</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>

</properties>
<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Application.properties file

    spring.data.elasticsearch.cluster-name=mycluster
spring.data.elasticsearch.cluster-nodes=localhost:9300

Output of my java program

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2022-04-22 20:53:48.890  INFO 18300 --- [  restartedMain] pringBootElasticsearchExampleApplication : Starting SpringBootElasticsearchExampleApplication on DESKTOP-ADQ0I0S with PID 18300 (started by Hp in D:\STS Project\demo)
2022-04-22 20:53:48.895  INFO 18300 --- [  restartedMain] pringBootElasticsearchExampleApplication : No active profile set, falling back to default profiles: default
2022-04-22 20:53:49.012  INFO 18300 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-04-22 20:53:49.012  INFO 18300 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-04-22 20:53:50.085  INFO 18300 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2022-04-22 20:53:50.169  INFO 18300 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 77ms. Found 1 repository interfaces.
2022-04-22 20:53:51.242  INFO 18300 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-04-22 20:53:51.280  INFO 18300 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-04-22 20:53:51.281  INFO 18300 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2022-04-22 20:53:51.302  INFO 18300 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\STS\sts-4.13.0.RELEASE\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/STS/sts-4.13.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657/jre/bin/server;D:/STS/sts-4.13.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657/jre/bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_202\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Hp\AppData\Local\Microsoft\WindowsApps;;C:\Users\Hp\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Hp\AppData\Roaming\npm;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Azure Data Studio\bin;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1\bin;;D:\STS\sts-4.13.0.RELEASE;;.]
2022-04-22 20:53:51.464  INFO 18300 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-04-22 20:53:51.464  INFO 18300 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2452 ms
2022-04-22 20:53:51.996  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : no modules loaded
2022-04-22 20:53:51.997  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2022-04-22 20:53:51.997  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2022-04-22 20:53:51.998  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2022-04-22 20:53:51.998  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2022-04-22 20:53:51.998  INFO 18300 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2022-04-22 20:53:53.600  INFO 18300 --- [  restartedMain] o.s.d.e.c.TransportClientFactoryBean     : Adding transport node : 127.0.0.1:9300
2022-04-22 20:53:53.962  INFO 18300 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-04-22 20:53:53.985 ERROR 18300 --- [  restartedMain] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{LsJSQJtCS56wr7IM_S0h4Q}{localhost}{127.0.0.1:9300}]
2022-04-22 20:53:54.354  INFO 18300 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2022-04-22 20:53:54.920  INFO 18300 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-04-22 20:53:54.924  INFO 18300 --- [  restartedMain] pringBootElasticsearchExampleApplication : Started SpringBootElasticsearchExampleApplication in 6.707 seconds (JVM running for 8.106)

Error I get on elasticsearch terminal as soon as I run the Java program

[2022-04-22T20:46:04,821][INFO ][o.e.i.g.DatabaseNodeService] [DESKTOP-ADQ0I0S] successfully loaded geoip database file [GeoLite2-City.mmdb]
[2022-04-22T20:53:53,786][WARN ][o.e.x.c.s.t.n.SecurityNetty4Transport] [DESKTOP-ADQ0I0S] received plaintext traffic on an encrypted channel, closing connection Netty4TcpChannel{localAddress=/127.0.0.1:9300, remoteAddress=/127.0.0.1:59255, profile=default}

To access Elasticsearch with Java I have followed this YouTube video tutorial [1]: https://www.youtube.com/watch?v=dlChXjE7IHw&t=541s

Also, im not able to add the type and shards parameter in the @Document annotation in my model. it is only accepting

@Document(indexName= "myindex")

According to the video it should be

@Document(indexName= "myindex" type="customer", shards=2)

elasticsearch.yml file

cluster.name: mycluster
path.data: D:\STS Project\demo
action.auto_create_index: .monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*
xpack.security.enabled: true

xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12

xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12

cluster.initial_master_nodes: ["DESKTOP-ADQ0I0S"]

http.host: [_local_, _site_]

CodePudding user response:

I was using transport client 9300 which is deprecated in Elasticsearch 7 and not supported in version 8 and I was using version 8.1.3. Here we can use the supported Elastic version 7.x or use Elasticsearch Java API client. [Elasticsearch Java API Client 8.1.3] Elasticsearch Java API Client 8.1.3

  • Related