@Override public Boolean execute(Client client) throws ElasticsearchException { if ((index != null) && (type != null) && (id != null)) { // Check if a document exists GetResponse response = client.prepareGet(index, type, id).setRefresh(true).execute().actionGet(); return response.isExists(); } else { // Check if index exists IndicesExistsResponse response = client.admin().indices().prepareExists(index).execute().actionGet(); return response.isExists(); } }
private void createUserID(final long userID) { final GetResponse getResponse = client .prepareGet(userIndex, userType, Long.toString(userID)) .setRefresh(true).execute().actionGet(); if (!getResponse.isExists()) { final Map<String, Object> source = new HashMap<>(); source.put("system_id", Long.toString(userID)); source.put(userIdField, userID); source.put(timestampField, new Date()); final IndexResponse response = client .prepareIndex(userIndex, userType, Long.toString(userID)) .setSource(source).setRefresh(true).execute().actionGet(); if (!response.isCreated()) { throw new TasteException("Failed to create " + source); } } }
@Override public Boolean execute(Client client) throws ElasticsearchException { if ((index != null) && (type != null) && (id != null)) { // Check if a document exists GetResponse response = client.prepareGet(index, type, id).setRefresh(true).execute().actionGet(); return response.isExists(); } else { // Check if index exists IndicesExistsResponse response = client.admin().indices().prepareExists(index).execute().actionGet(); return response.isExists(); } }
/** * Check if a document exists in E.S. * * @param index * Index Name * @param id * Document ID * @return true/false * @throws ElasticsearchException */ private Boolean doesExist(String index, String id) { if (StringUtils.isEmpty(id)) { return false; } GetResponse response = client.prepareGet(index, index, id).setRefresh(true).get(); return response.isExists(); }
private void createItemID(final long itemID) { final GetResponse getResponse = client .prepareGet(itemIndex, itemType, Long.toString(itemID)) .setRefresh(true).execute().actionGet(); if (!getResponse.isExists()) { final Map<String, Object> source = new HashMap<>(); source.put("system_id", Long.toString(itemID)); source.put(itemIdField, itemID); source.put(timestampField, new Date()); final IndexResponse response = client .prepareIndex(itemIndex, itemType, Long.toString(itemID)) .setSource(source).setRefresh(true).execute().actionGet(); if (!response.isCreated()) { throw new TasteException("Failed to create " + source); } } }
private void reloadConfig() { client.prepareGet(securityConfigurationIndex, "ac", "ac").setRefresh(true).execute(new ActionListener<GetResponse>() { @Override public void onResponse(final GetResponse response) { if (response.isExists() && !response.isSourceEmpty()) { securityConfiguration = response.getSourceAsBytesRef(); latch.countDown(); logger.debug("Security configuration reloaded"); } } @Override public void onFailure(final Throwable e) { if (e instanceof IndexMissingException) { logger.debug( "Try to refresh security configuration but it failed due to {} - This might be ok if security setup not complete yet.", e.toString()); } else { logger.error("Try to refresh security configuration but it failed due to {}", e, e.toString()); } } }); }
public BytesReference getXContentSecurityConfigurationAsBR( final String type, final String id) throws MalformedConfigurationException { final GetResponse resp = client .prepareGet(securityConfigurationIndex, type, id) .setRefresh(true).setOperationThreaded(false).get(); if (resp.isExists()) { return resp.getSourceAsBytesRef(); } else { throw new MalformedConfigurationException("document type " + type + " with id " + id + " does not exists"); } }
if (options.getRouting() != null) builder.setRouting(options.getRouting()); if (options.getParent() != null) builder.setParent(options.getParent()); if (options.isRefresh() != null) builder.setRefresh(options.isRefresh()); if (options.getVersion() != null) builder.setVersion(options.getVersion()); if (options.getVersionType() != null) builder.setVersionType(options.getVersionType());