Last active
September 14, 2018 14:26
-
-
Save spati-java/f851599cf6abb649895fd098e79daf4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| @Slf4j | |
| public class ProfileService { | |
| private RestHighLevelClient client; | |
| private ObjectMapper objectMapper; | |
| @Autowired | |
| public ProfileService(RestHighLevelClient client, ObjectMapper objectMapper) { | |
| this.client = client; | |
| this.objectMapper = objectMapper; | |
| } | |
| public String createProfile(ProfileDocument document) throws Exception { | |
| UUID uuid = UUID.randomUUID(); | |
| document.setId(uuid.toString()); | |
| Map<String, Object> documentMapper = objectMapper.convertValue(document, Map.class); | |
| IndexRequest indexRequest = new IndexRequest(INDEX, TYPE, document.getId()) | |
| .source(documentMapper); | |
| IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); | |
| return indexResponse | |
| .getResult() | |
| .name(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment