public GetRequestBuilder prepareGet(IndexType indexType, String id) { return new ProxyGetRequestBuilder(nativeClient()).setIndex(indexType.getIndex()).setType(indexType.getType()).setId(id); }
@Override public GetRequestBuilder prepareGet(String index, String type, String id) { return prepareGet().setIndex(index).setType(type).setId(id); }
private static GetRequestBuilder prepareGetIndex(Object object, Client client) { @SuppressWarnings("unchecked") Map<String, String> indexInformation = (Map<String, String>) object; GetRequestBuilder prepareGet = client.prepareGet(); if (indexInformation.containsKey(DataReader.INDEX_NAME_ELEMENT)) { prepareGet.setIndex(indexInformation.get(DataReader.INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_TYPE_ELEMENT)) { prepareGet.setType(indexInformation.get(DataReader.INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_ID_ELEMENT)) { prepareGet.setId(indexInformation.get(DataReader.INDEX_ID_ELEMENT)); } return prepareGet; }
private static GetRequestBuilder prepareGetIndex(Object object, Client client) { @SuppressWarnings("unchecked") Map<String, String> indexInformation = (Map<String, String>) object; GetRequestBuilder prepareGet = client.prepareGet(); if (indexInformation.containsKey(DataReader.INDEX_NAME_ELEMENT)) { prepareGet.setIndex(indexInformation.get(DataReader.INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_TYPE_ELEMENT)) { prepareGet.setType(indexInformation.get(DataReader.INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_ID_ELEMENT)) { prepareGet.setId(indexInformation.get(DataReader.INDEX_ID_ELEMENT)); } return prepareGet; }
private static GetRequestBuilder prepareGetIndex(Object object, Client client) { Map<String, String> indexInformation = (Map<String, String>) object; GetRequestBuilder prepareGet = client.prepareGet(); if (indexInformation.containsKey(DataReader.INDEX_NAME_ELEMENT)) { prepareGet.setIndex(indexInformation.get(DataReader.INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_TYPE_ELEMENT)) { prepareGet.setType(indexInformation.get(DataReader.INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_ID_ELEMENT)) { prepareGet.setId(indexInformation.get(DataReader.INDEX_ID_ELEMENT)); } return prepareGet; }
private static GetRequestBuilder prepareGetIndex(Object object, Client client) { Map<String, String> indexInformation = (Map<String, String>) object; GetRequestBuilder prepareGet = client.prepareGet(); if (indexInformation.containsKey(DataReader.INDEX_NAME_ELEMENT)) { prepareGet.setIndex(indexInformation.get(DataReader.INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_TYPE_ELEMENT)) { prepareGet.setType(indexInformation.get(DataReader.INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_ID_ELEMENT)) { prepareGet.setId(indexInformation.get(DataReader.INDEX_ID_ELEMENT)); } return prepareGet; }
private static GetRequestBuilder prepareGetIndex(Object object, Client client) { @SuppressWarnings("unchecked") Map<String, String> indexInformation = (Map<String, String>) object; GetRequestBuilder prepareGet = client.prepareGet(); if (indexInformation.containsKey(DataReader.INDEX_NAME_ELEMENT)) { prepareGet.setIndex(indexInformation.get(DataReader.INDEX_NAME_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_TYPE_ELEMENT)) { prepareGet.setType(indexInformation.get(DataReader.INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(DataReader.INDEX_ID_ELEMENT)) { prepareGet.setId(indexInformation.get(DataReader.INDEX_ID_ELEMENT)); } return prepareGet; }
@Override public GetRequestBuilder prepareGet(String index, String type, String id) { return prepareGet().setIndex(index).setType(type).setId(id); }
@Override public GetRequestBuilder prepareGet(final String index, @Nullable final String type, final String id) { return new GetRequestBuilder(this, index).setType(type).setId(id); }
@Override public GetRequestBuilder prepareGet(String index, String type, String id) { return prepareGet().setIndex(index).setType(type).setId(id); }
@Override public GetRequestBuilder prepareGet(String index, String type, String id) { return prepareGet().setIndex(index).setType(type).setId(id); }
@Override public GetRequestBuilder prepareGet(final String index, @Nullable final String type, final String id) { return new GetRequestBuilder(this, index).setType(type).setId(id); }
private String getLastUpdatedTimestamp() { GetResponse lastUpdatedTimestampResponse = client.prepareGet().setIndex(riverIndexName).setType(riverName.name()).setId("lastUpdatedTimestamp").execute().actionGet(); if (lastUpdatedTimestampResponse.isExists() && lastUpdatedTimestampResponse.getSource().containsKey("lastUpdatedTimestamp")) { return lastUpdatedTimestampResponse.getSource().get("lastUpdatedTimestamp").toString(); } return null; } }
/** * Returns the source (a map of fields and values) for and object. * The source is extracted from the index directly not the data store. * @param appid name of the {@link com.erudika.para.core.App} * @param key the object id * @param type type of object * @return a map representation of the object */ protected Map<String, Object> getSource(String appid, String key, String type) { Map<String, Object> map = new HashMap<String, Object>(); if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) { return map; } try { GetRequestBuilder grb = client().prepareGet(). setIndex(getIndexName(appid)).setId(key); if (!StringUtils.isBlank(type)) { grb.setType(type); } map = grb.execute().actionGet().getSource(); } catch (Exception e) { logger.warn(null, e); } return map; }
@Override public boolean isProductExists(final ElasticSearchIndexConfig config, final Long productId) { return searchClientService.getClient().prepareGet() .setIndex(config.getIndexAliasName()) .setId(String.valueOf(productId)).get().isExists(); }
@Override public boolean isProductExists(ElasticSearchIndexConfig config, Long productId) { return searchClientService.getClient().prepareGet().setIndex(config.getIndexAliasName()) .setId(String.valueOf(productId)) .get() .isExists(); }
/** * 根据id查询 * * @param id 主键id * @param index 索引 * @param type 类型 * @return 返回查询得到的 */ public String searchById(String index, String type, String id) { String jsonString = null; try { GetResponse response = client.prepareGet() .setId(id) .setIndex(index) .setType(type) .execute() .actionGet(); jsonString = response.getSourceAsString(); } catch (Exception e) { EsLogUtils.error("{},ES查询报错:索引:{};id:{};{}", type, index, id, e.getMessage()); return jsonString; } return jsonString; }
@Override protected ElasticsearchDocumentHistory loadExistingDocumentHistory(String documentId) throws BaleenException { try { GetResponse response = new GetRequestBuilder(elasticsearch.getClient(), GetAction.INSTANCE) .setId(documentId) .setIndex(esIndex) .setType(esType) .get(); if (!response.isExists() || response.isSourceEmpty()) { // If we don't have any data, then let parent implementation create a new history return null; } else { ESHistory esh = mapper.readValue(response.getSourceAsBytes(), ESHistory.class); if (esh == null) { return new ElasticsearchDocumentHistory( this, documentId, new LinkedBlockingDeque<HistoryEvent>(Collections.emptyList())); } else { return new ElasticsearchDocumentHistory( this, documentId, new LinkedBlockingDeque<HistoryEvent>(esh.getEvents())); } } } catch (IOException e) { throw new BaleenException(e); } } }
@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(); }
public GetRequestBuilder prepareGet(IndexType indexType, String id) { return new ProxyGetRequestBuilder(nativeClient()).setIndex(indexType.getIndex()).setType(indexType.getType()).setId(id); }