public boolean addDocument(JsonElement docJson, String _id, boolean bAllowOverwrite, String sParentId) {
if (null != _multiIndex) {
throw new RuntimeException("addDocument not supported on multi-index manager");
}
IndexRequestBuilder irb = _elasticClient.prepareIndex(_sIndexName, _sIndexType).setSource(docJson.toString());
if (null != _id) {
irb.setId(_id);
}//TESTED
else { // If an _id is already specified use that
JsonElement _idJson = docJson.getAsJsonObject().get("_id");
if (null != _idJson) {
_id = _idJson.getAsString();
if (null != _id) {
irb.setId(_id);
}
}
}//TOTEST
if (!bAllowOverwrite) {
irb.setOpType(OpType.CREATE);
}//TESTED
if (null != sParentId) {
irb.setParent(sParentId);
}
// This ensures that the write goes through if I can write to any nodes, which seems sensible
// You could always check the response and handle minimal success like failure if you want
irb.setConsistencyLevel(WriteConsistencyLevel.ONE);
try {
irb.execute().actionGet();
}
catch (org.elasticsearch.transport.RemoteTransportException e) {
boolean bDocAlreadyExists =
e.contains(org.elasticsearch.index.engine.DocumentAlreadyExistsEngineException.class) // 0.18
||