Skip to content

Instantly share code, notes, and snippets.

@GetMapping
public List<ProfileDocument> findAll() throws Exception {
return service.findAll();
}
public String deleteProfileDocument(String id) throws Exception {
DeleteRequest deleteRequest = new DeleteRequest(INDEX, TYPE, id);
DeleteResponse response =
client.delete(deleteRequest, RequestOptions.DEFAULT);
return response
.getResult()
.name();
public List<ProfileDocument> findAll() throws Exception {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse =
client.search(searchRequest, RequestOptions.DEFAULT);
public String updateProfile(ProfileDocument document) throws Exception {
ProfileDocument resultDocument = findById(document.getId());
UpdateRequest updateRequest = new UpdateRequest(
INDEX,
TYPE,
resultDocument.getId());
Map<String, Object> documentMapper =
public ProfileDocument findById(String id) throws Exception {
GetRequest getRequest = new GetRequest(INDEX, TYPE, id);
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
Map<String, Object> resultMap = getResponse.getSource();
return objectMapper
.convertValue(resultMap, ProfileDocument.class);
@Service
@Slf4j
public class ProfileService {
private RestHighLevelClient client;
private ObjectMapper objectMapper;
@Autowired
public ProfileService(RestHighLevelClient client, ObjectMapper objectMapper) {
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
@Data
public class ProfileDocument {
private String id;
private String firstName;
private String lastName;
private List<Technologies> technologies;
private List<String> emails;
}
elasticsearch.host=search-dev-elasticsearch-5bgsa4vpjib46bgh4cbtebsxydiq.us-east-1.es.amazonaws.com