.prepareGet(indexName, typeName, id) .setOperationThreaded(false) .setFields(new String[]{}) .execute() .actionGet();
public ElasticsearchSample get(Object key, String... fields) { GetResponse getResponse = client.prepareGet(index, type, String.valueOf(key)).setFields(fields).execute() .actionGet(); Map<String, Object> map = new TreeMap<String, Object>(); map.put(ID, getResponse.getId()); for (String k : getResponse.getFields().keySet()) { map.put(k, getResponse.getField(k).getValue()); } return new ElasticsearchSample(this, map); }
public Long checkpointedAt(String id) throws IOException { GetResponse response = client.prepareGet(pubSubIndexName, TYPE, id) .setFields("timestamp") .execute().actionGet(); boolean failed = !response.isExists(); if (failed) { logger.warn("can't get checkpoint for {}", id); return null; } else { return (Long) response.getFields().get("timestamp").getValue(); } }
@Override public <T> boolean exist(Class<T> clazz, String id) { return getClient().prepareGet(getIndexForType(clazz), MappingBuilder.indexTypeFromClass(clazz), id).setFields(new String[0]).execute().actionGet() .isExists(); }
@Override public int getFlaghashcode(final String id) throws IOException, MessagingException { createIndexIfNotExists(); client.admin().indices().refresh(new RefreshRequest()).actionGet(); final GetResponse getResponse = client.prepareGet().setIndex(index).setType(type).setId(id) .setFields(new String[] { "flaghashcode" }).execute().actionGet(); if (getResponse == null || !getResponse.isExists()) { return -1; } final GetField flaghashcodeField = getResponse.getField("flaghashcode"); if (flaghashcodeField == null || flaghashcodeField.getValue() == null || !(flaghashcodeField.getValue() instanceof Number)) { throw new IOException("No flaghashcode field for id " + id+ " ("+(flaghashcodeField==null?"null":"Val: "+flaghashcodeField.getValue())+")"); } return ((Number) flaghashcodeField.getValue()).intValue(); }
getRequestBuilder.setFields("*", "_timestamp"); getRequestBuilder.setFetchSource(true); GetResponse getResponse = getRequestBuilder.get();
private GetResponse getParentDocument(IndexInfo indexInfo, String elementId) { try { GetResponse response = getClient() .prepareGet(indexInfo.getIndexName(), ELEMENT_TYPE, elementId) .setFields(getParentDocumentFields()) .execute() .get(); if (!response.isExists()) { return null; } return response; } catch (Exception ex) { throw new SecureGraphException("Could not get parent document: " + elementId, ex); } }
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = new ArrayList<>(); if (entry == null || entry.getMetadata() == null) { return result; } Map<String, Object> metadata = entry.getMetadata(); String index = ElasticsearchMetadataUtil.getIndex(metadata, config); String type = ElasticsearchMetadataUtil.getType(metadata, config); String id = ElasticsearchMetadataUtil.getId(entry); GetRequestBuilder getRequestBuilder = elasticsearchClientManager.client().prepareGet(index, type, id); getRequestBuilder.setFields("*", "_timestamp"); getRequestBuilder.setFetchSource(true); GetResponse getResponse = getRequestBuilder.get(); if ( getResponse == null || !getResponse.isExists() || getResponse.isSourceEmpty() ) { return result; } entry.setDocument(getResponse.getSource()); if ( getResponse.getField("_timestamp") != null) { DateTime timestamp = new DateTime(((Long) getResponse.getField("_timestamp").getValue()).longValue()); entry.setTimestamp(timestamp); } result.add(entry); return result; }
.setFields(SearchDocumentFieldName.productDocumentFields) .get(); if(getResponse.isExists())
private GetResponse getParentDocument(IndexInfo indexInfo, String elementId) { try { GetResponse response = getClient() .prepareGet(indexInfo.getIndexName(), ELEMENT_TYPE, elementId) .setFields(getParentDocumentFields()) .execute() .get(); if (!response.isExists()) { return null; } return response; } catch (Exception ex) { throw new VertexiumException("Could not get parent document: " + elementId, ex); } }
.prepareGet(config.getIndexAliasName(), config.getDocumentType(), String.valueOf(productId)) .setFields(SearchDocumentFieldName.productDocumentFields).get(); if (getResponse.isExists()) { final Product product = new Product();
@Override public UserIdentity loadUser(String user) { Log.debug("attempting to load user [{}]", user); try { GetResponse response = client.prepareGet(authIndex, authType, user) .setFields(passwordField, rolesField) .execute().actionGet(); if (response.isExists()) { Log.debug("user [{}] exists; looking for credentials...", user); Credential credential = null; GetField passwordGetField = response.getField(passwordField); if (passwordGetField != null) { Log.debug("user [{}] using password auth", user); credential = Credential.getCredential((String) passwordGetField.getValue()); } String[] roles = getStringValues(response.getField(rolesField)); return putUser(user, credential, roles); } } catch (IndexMissingException e) { Log.warn("no auth index [{}]", authIndex); } catch (Exception e) { Log.warn("error finding user [" + user + "] in [" + authIndex + "]", e); } return null; }
builder.setFields(options.getFields().toArray(new String[options.getFields().size()]));