Skip to content

Instantly share code, notes, and snippets.

@siminoushad
Created August 1, 2012 11:02
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 siminoushad/3225800 to your computer and use it in GitHub Desktop.
Save siminoushad/3225800 to your computer and use it in GitHub Desktop.
Elasticsearch client
IndexResponse response = null;
IndexRequestBuilder indexRreqBuild;
client.admin()
.cluster()
.health(new ClusterHealthRequest(indexName)
.waitForYellowStatus()).actionGet();
XContentBuilder docBuilder = XContentFactory.jsonBuilder()
.startObject();
for (String key : map.keySet()) {
docBuilder.field(key, map.get(key));
}
docBuilder.endObject();
indexRreqBuild = client.prepareIndex(indexName, indexType)
.setConsistencyLevel(WriteConsistencyLevel.DEFAULT)
.setSource(docBuilder);
response = indexRreqBuild.execute().actionGet();
indexId = response.getId();
client.admin().indices().refresh(new RefreshRequest(indexName))
.actionGet();
return indexId;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment