GetResponse getResponse = elasticsearchClient .prepareGet(indexName, typeName, id) .setOperationThreaded(false) .setFields(new String[]{}) .execute()
GetResponse getResponse = elasticsearchClient .prepareGet(indexName, typeName, id) .setOperationThreaded(false) .execute() .actionGet();
.setOperationThreaded(false).execute().get();
/** * 查询一条索引 * @param index * @param type * @param id */ public static GetResponse prepareGet(String index, String type, String id){ GetResponse response = getInstance().prepareGet(index, type, id).setOperationThreaded(true).get(); return response; }
@SuppressWarnings("unchecked") private void addUuidToMetadataIfNeeded(String uuid) throws ElasticsearchException { GetResponse resp = client .prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID) .setOperationThreaded(false).get(); Object retValues = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName()); List<String> values; if (retValues instanceof String) { values = new LinkedList<>(); values.add((String) retValues); } else if (retValues instanceof List<?>) { values = (List<String>) retValues; } else { throw new ConfigurationError("Invalid %s field type %s should have String or java.util.Collection<String>", MetadataDataMapping.METADATA_UUIDS_FIELD, retValues.getClass()); } // add new uuid if needed if (!values.stream().anyMatch(m -> m.equals(uuid))) { Map<String, Object> uuids = new HashMap<>(); values.add(uuid); uuids.put(MetadataDataMapping.METADATA_UUIDS_FIELD.getName(), values); uuids.put(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName(), Calendar.getInstance(DateTimeZone.UTC .toTimeZone())); client.prepareUpdate(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, "1").setDoc(uuids).get(); logger.info("UUID {} is added to the {} type", uuid, MetadataDataMapping.METADATA_TYPE_NAME); } }
private Integer getCurrentVersion() { GetResponse resp = client.prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID) .setOperationThreaded(false).get(); if (resp.isExists()) { Object versionString = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_VERSION_FIELD.getName()); if (versionString == null) { throw new ElasticsearchException(String .format("Database inconsistency. Version can't be found in row %s/%s/%s", settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID)); } return Integer.valueOf(versionString.toString()); } else { return null; } }
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"); } }
private UserData getUser(String userName) { GetResponse response = null; try { response = client.prepareGet(HTTP_USER_AUTH_INDEX, HTTP_USER_AUTH_TYPE, userName) .setOperationThreaded(false) .execute() .get(); } catch (InterruptedException | ExecutionException e) { EFLogger.error("InterruptedException | ExecutionException", e); } if (response != null && response.isExists()) { return getUserDataFromESSource(response.getSource()); } return null; }
.setOperationThreaded(false).execute().get();
keyAsString).setOperationThreaded(false).execute().get();