# Spring data opensearch example not working

**URL:** <https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033>\
**Category:** OpenSearch\
**Tags:** troubleshoot\
**Created:** [December 11, 2023, 6:24pm UTC](https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033 "2023-12-11T18:24:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcwik](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@dcwik](https://forum.opensearch.org/u/dcwik)\
**Post date:** [December 11, 2023, 6:24pm UTC](https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033/1 "2023-12-11T18:24:38Z")

</div>

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

**Describe the issue** :  
I try to run [Spring data opensearch example](https://github.com/opensearch-project/spring-data-opensearch/tree/main/spring-data-opensearch-examples/spring-boot-gradle). 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?

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [December 11, 2023, 8:45pm UTC](https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033/2 "2023-12-11T20:45:58Z")

</div>

@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](https://github.com/opensearch-project/spring-data-opensearch/blob/main/spring-data-opensearch-examples/spring-boot-gradle/README.md)):

```auto
$ ./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

---

<div class="post-metadata">

**Author:** ![dcwik](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@dcwik](https://forum.opensearch.org/u/dcwik)\
**Post date:** [July 31, 2024, 6:20pm UTC](https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033/3 "2024-07-31T18:20:25Z")

</div>

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](https://github.com/opensearch-project/spring-data-opensearch/tree/main/spring-data-opensearch-examples/spring-boot-gradle)) everything works great. README.md examples are working.  
Unfortunately when I run spring-boot-java-client-gradle ([example](https://github.com/opensearch-project/spring-data-opensearch/tree/main/spring-data-opensearch-examples/spring-boot-java-client-gradle)) and execute curl command from README.md, exception is thrown.

```auto
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]

```

```auto
curl 'http://localhost:8080/marketplace/search'
{
  "timestamp" : "2024-07-31T18:19:50.557+00:00",
  "status" : 500,
  "error" : "Internal Server Error",
  "path" : "/marketplace/search"
}

```

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [July 31, 2024, 8:46pm UTC](https://forum.opensearch.org/t/spring-data-opensearch-example-not-working/17033/4 "2024-07-31T20:46:35Z")

</div>

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](https://github.com/opensearch-project/spring-data-opensearch/pull/320) , thank you @dcwik
