5

I'm trying to add AWS OpenSearch to my project, which is based on Spring Boot 3.

I already created AWS OpenSearch, and then I want to connect from Spring Boot application to AWS OpenSearch. However, It is very hard to find a tutorial for doing that whereas there are lots of tutorials to know about AWS OpenSearch itself.

It may be very silly question, but is there someone who can give me the guidance website to connect to AWS OpenSearch from Spring Boot 3?

I've tried to google to find out how to connect to the AWS OpenSearch from Spring Boot 3, but I couldn't find a proper one. I'd like to want to find some documents or guidances to do that.

4
  • did you find the solution? Commented Jun 25, 2024 at 7:39
  • Have you figured out the way to connect with aws open search locally using spring boot Commented Jul 19, 2024 at 17:44
  • Same problem, could you find a solution/tutorial ? Commented Jul 27, 2024 at 15:11
  • Hi, I just noticed these comments and I hope you already figured it out. Otherwise, it may help for you. github.com/daedongbread/bread-map-backend-2/blob/develop/src/… Commented Jul 31, 2024 at 10:36

1 Answer 1

2

After spending a week, here is what I got.

Overall flow : use logger (slf4j) to add logs in your java file -> filebeat (oss version) -> aws OpenSearch

Step 1: Configure Spring Boot Application

  • Add these dependency in your pom file
<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>1.2.11</version>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-logging</artifactId>
</dependency>

  • Add logback.xml in your resources folder
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/app/your-file-path/application.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>/app/your-file-path/application.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="info">
    <appender-ref ref="FILE" />
</root>
</configuration>

Step 2: Install Filebeat (or logstash or both) on your ec2 instance.

If you have a better server than t2.micro, you can use Logstash here, which is better but needs more resources. Full installation guide for filebeat - click here

check logs for any error: sudo journalctl -u filebeat.

Make sure you install the oss(open-source) version otherwise, it will look for the license and will throw an error.

Step 3: Set up your opensearch. (which I guess you have already done).

Once filebeat start sending logs to your opensearch , navigate to Dashboard management > index pattern and type filebeat-* and follow the steps.

Hope it helps :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.