Skip to content

Instantly share code, notes, and snippets.

@spati-java
Last active September 14, 2018 14:26
Show Gist options
  • Select an option

  • Save spati-java/f851599cf6abb649895fd098e79daf4b to your computer and use it in GitHub Desktop.

Select an option

Save spati-java/f851599cf6abb649895fd098e79daf4b to your computer and use it in GitHub Desktop.
@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