Skip to content

Instantly share code, notes, and snippets.

package com.cb.controller;
import com.cb.model.Book;
import com.cb.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
package com.cb.service;
import java.util.List;
public class SearchResult<T> {
private List<T> results;
private long totalRecords;
private int totalPages;
public SearchResult(List<T> results, long totalRecords, int totalPages) {
package com.cb.service;
import com.cb.model.Book;
import com.cb.repository.BookRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.client.RequestOptions;
import org.opensearch.client.RestHighLevelClient;
import org.opensearch.index.query.QueryBuilders;
package com.cb.repository;
import com.cb.model.Book;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.util.UUID;
/**
* Repository interface for managing Book entities in OpenSearch.
* Extends ElasticsearchRepository to provide CRUD operations and custom query methods.
package com.cb.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
/**
* Represents a book document in the OpenSearch index.
spring:
application:
# The name of the Spring Boot application.
name: spring-boot-opensearch
server:
# The port on which the server will run.
port: 8081
opensearch:
# The URI of the AWS OpenSearch cluster.
uris: https://search-xxx-xxx.ap-south-1.es.amazonaws.com
<?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>3.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
package com.example.fulfillment.model;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class FulfillmentOptionsResponse {
private String dpeHdData;
private String dpeCncData;
spring.application.name=concurrent-service-calls-spring-boot-completable-future
order.service.url=http://localhost:8081
customer.service.url=http://localhost:8082
inventory.service.url=http://localhost:8083
package com.cb.controller;
import com.cb.model.OrderSummary;
import com.cb.service.OrderAggregationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;