Skip to content

Instantly share code, notes, and snippets.

@talfco
Last active May 21, 2020 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talfco/eb8ab20bfafe2359b120668d5655dcc1 to your computer and use it in GitHub Desktop.
Save talfco/eb8ab20bfafe2359b120668d5655dcc1 to your computer and use it in GitHub Desktop.
Updating a ElasticSearch Document
public void createUpdateDocument(String index, String type, String docJson, String id) throws IOException {
Index esIndex;
if (id == null) {
esIndex = new Index.Builder(docJson).index(index).type(type).build();
} else {
esIndex = new Index.Builder(docJson).index(index).type(type).id(id).build();
}
JestResult jestResult = esClient.execute(esIndex);
if(jestResult.isSucceeded()) {
logger.info("Document persisted");
}
else {
logger.error(jestResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment