Spring data opensearch example not working

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

Describe the issue:
I try to run Spring data opensearch example. Unfortunatelly it does not work.
I receive build error

/spring-data-opensearch/buildSrc/build/tmp/generatePrecompiledScriptPluginAccessors/accessors10801111436889098915

Configuration:

Spring boot 3.2
Spring data opensearch starter 1.3.0
Java 17

How to run example provided by opensearch-project?

@dcwik to run example please check the README.md (https://github.com/opensearch-project/spring-data-opensearch/blob/main/spring-data-opensearch-examples/spring-boot-gradle/README.md):

$ ./gradlew :spring-data-opensearch-examples:spring-boot-gradle:bootRun

> Task :spring-data-opensearch-examples:spring-boot-gradle:bootRun
default THREAD FACTORY

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.0)

2023-12-11T15:43:38.434-05:00  INFO 273886 --- [           main] o.o.data.example.MarketplaceApplication  : Starting MarketplaceApplication using Java 17.0.9 with PID 273886 (/home/spring-data-opensearch/spring-data-opensearch-examples/spring-boot-gradle/build/classes/java/main started by user in /home/spring-data-opensearch/spring-data-opensearch-examples/spring-boot-gradle)
2023-12-11T15:43:38.436-05:00  INFO 273886 --- [           main] o.o.data.example.MarketplaceApplication  : No active profile set, falling back to 1 default profile: "default"
2023-12-11T15:43:38.670-05:00  INFO 273886 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2023-12-11T15:43:38.693-05:00  INFO 273886 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20 ms. Found 1 Elasticsearch repository interface.
2023-12-11T15:43:39.015-05:00  INFO 273886 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2023-12-11T15:43:39.021-05:00  INFO 273886 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-11T15:43:39.021-05:00  INFO 273886 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.16]
2023-12-11T15:43:39.056-05:00  INFO 273886 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-11T15:43:39.057-05:00  INFO 273886 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 597 ms
2023-12-11T15:43:40.826-05:00  INFO 273886 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2023-12-11T15:43:40.832-05:00  INFO 273886 --- [           main] o.o.data.example.MarketplaceApp

Please share more details on how you are trying to start the example, thank you

Hello, i want to refresh this topic.

I pulled spring-data-opensearch repository. I run opensearch in docker. I configured properties to connect to my opensearch.

As for spring-boot-gradle (example) everything works great. README.md examples are working.
Unfortunately when I run spring-boot-java-client-gradle (example) and execute curl command from README.md, exception is thrown.

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.DataAccessResourceFailureException: Connection is closed] with root cause

org.apache.http.ConnectionClosedException: Connection is closed
	at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:356) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:261) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:87) ~[httpasyncclient-4.1.5.jar:4.1.5]
	at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:40) ~[httpasyncclient-4.1.5.jar:4.1.5]
	at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.16.jar:4.4.16]
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.16.jar:4.4.16]
curl 'http://localhost:8080/marketplace/search'
{
  "timestamp" : "2024-07-31T18:19:50.557+00:00",
  "status" : 500,
  "error" : "Internal Server Error",
  "path" : "/marketplace/search"
}

Ah, this is sniffer’s fault, updated the examples here Exclude 'opensearch-rest-client-sniffer' from examples since Docker reports non-HTTPs address for container by default by reta · Pull Request #320 · opensearch-project/spring-data-opensearch · GitHub , thank you @dcwik

1 Like