- Docker Compose
- Pip
Install Localstack awslocal
. It uses awscli version 1.
Reference: LocalStack awslocal limitations
pip install awscli-local[ver1]
Now download docker-compose.yml
, open terminal at the root of the project and run the following command
Reference: LocalStack install OpenSearch
docker-compose -f ./docker/opensearch/docker-compose.yml up -d
Now run the following command to create OpenSearch domain
awslocal opensearch create-domain --domain-name my-domain --endpoint-url http://localhost:4566
Create this configuration class
@Configuration
class OpenSearchConfig {
@Bean
fun restHighLevelClient(): RestHighLevelClient {
val builder = RestClient.builder(
HttpHost.create("http://localhost.localstack.cloud:4566"))
.setPathPrefix("/opensearch/us-east-1/my-domain")
return RestHighLevelClient(builder)
}
}
and this controller
@RestController
@RequestMapping("search")
class SearchController(
val client: RestHighLevelClient,
) {
@GetMapping()
@ResponseStatus(HttpStatus.OK)
fun getSearch(searchRequest: SearchRequest) = client.search(searchRequest, RequestOptions.DEFAULT)
}
Now you can GET http://localhost:8080/search
or
GET http://localhost.localstack.cloud:4566/opensearch/us-east-1/my-domain