/** * Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard * elements. * * @param include An optional include (optionally wildcarded) pattern to filter the returned _source * @param exclude An optional exclude (optionally wildcarded) pattern to filter the returned _source */ public GetRequestBuilder setFetchSource(@Nullable String include, @Nullable String exclude) { return setFetchSource( include == null ? Strings.EMPTY_ARRAY : new String[]{include}, exclude == null ? Strings.EMPTY_ARRAY : new String[]{exclude}); }
/** * Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard * elements. * * @param include An optional include (optionally wildcarded) pattern to filter the returned _source * @param exclude An optional exclude (optionally wildcarded) pattern to filter the returned _source */ public GetRequestBuilder setFetchSource(@Nullable String include, @Nullable String exclude) { return setFetchSource( include == null ? Strings.EMPTY_ARRAY : new String[]{include}, exclude == null ? Strings.EMPTY_ARRAY : new String[]{exclude}); }
/** * Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard * elements. * * @param include An optional include (optionally wildcarded) pattern to filter the returned _source * @param exclude An optional exclude (optionally wildcarded) pattern to filter the returned _source */ public GetRequestBuilder setFetchSource(@Nullable String include, @Nullable String exclude) { return setFetchSource( include == null ? Strings.EMPTY_ARRAY : new String[]{include}, exclude == null ? Strings.EMPTY_ARRAY : new String[]{exclude}); }
/** * Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard * elements. * * @param include An optional include (optionally wildcarded) pattern to filter the returned _source * @param exclude An optional exclude (optionally wildcarded) pattern to filter the returned _source */ public GetRequestBuilder setFetchSource(@Nullable String include, @Nullable String exclude) { return setFetchSource( include == null ? Strings.EMPTY_ARRAY : new String[]{include}, exclude == null ? Strings.EMPTY_ARRAY : new String[]{exclude}); }
/** * Indicate that _source should be returned, with an "include" and/or "exclude" set which can include simple wildcard * elements. * * @param include An optional include (optionally wildcarded) pattern to filter the returned _source * @param exclude An optional exclude (optionally wildcarded) pattern to filter the returned _source */ public GetRequestBuilder setFetchSource(@Nullable String include, @Nullable String exclude) { return setFetchSource( include == null ? Strings.EMPTY_ARRAY : new String[]{include}, exclude == null ? Strings.EMPTY_ARRAY : new String[]{exclude}); }
@SuppressWarnings("unchecked") @Override public Optional<T> findOne(final String id) { final GetResponse response = client .prepareGet(index, type, id) .setFetchSource(true) .execute() .actionGet(); final String json = response.getSourceAsString(); return ofNullable(json) .map(deserializer) .map(e -> (T) e.withId(id)); }
/** * 通过ID获取数据 * * @param index 索引,类似数据库 * @param type 类型,类似表 * @param id 数据ID * @param fields 需要显示的字段,逗号分隔(缺省为全部字段) * @return */ public static Map<String, Object> searchDataById(String index, String type, String id, String fields) { GetRequestBuilder getRequestBuilder = client.prepareGet(index, type, id); if (StringUtils.isNotEmpty(fields)) { getRequestBuilder.setFetchSource(fields.split(","), null); } GetResponse getResponse = getRequestBuilder.execute().actionGet(); return getResponse.getSource(); }
@Override public boolean exists(final String id) { final GetResponse response = client .prepareGet(index, type, id) .setFetchSource(false) .execute() .actionGet(); return response.isExists(); }
public Object getField(String id, String field){ GetResponse response = client.prepareGet(this.indexName, this.documentType, id) .setFetchSource(field,null) // .setStoredFields(field) .execute() .actionGet(); Object res = null; if (response==null){ if (logger.isWarnEnabled()){ logger.warn("no response from document "+id+" when fetching field "+field+"!"); } return null; }else { res = response.getSourceAsMap().get(field); if (res==null){ if (logger.isWarnEnabled()) { logger.warn("document " + id + " has no field " + field + "!"); } } } return res; // return response.getField(field).getValue(); }
public NamedQuery get(String name) { GetResponse response = getConnection().getClient() .prepareGet(getIndex(), getType(), name.toLowerCase()) .setFetchSource(true) .get(); if (response.isExists()) { return mapToNamedQuery(response.getSource()); } return null; }
@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; }
public HttpSource get(String url) { GetResponse response = getConnection().getClient().prepareGet(getIndex(), getType(), url) .setFetchSource(true) .get(); if (response.isExists()) { return mapToHttpSource(response.getSource()); } return null; }
public HttpSourceTest get(String url) { GetResponse response = getConnection().getClient().prepareGet(getIndex(), getType(), url) .setFetchSource(true) .get(); if (response.isExists()) { return mapToHttpSourceTest(response.getSource()); } return null; }
getRequestBuilder.setFetchSource(true); GetResponse getResponse = getRequestBuilder.get();
builder.setFields(options.getFields().toArray(new String[options.getFields().size()])); if (options.isFetchSource() != null) builder.setFetchSource(options.isFetchSource()); if (!options.getFetchSourceIncludes().isEmpty() || !options.getFetchSourceExcludes().isEmpty()) { String[] includes = options.getFetchSourceIncludes().toArray(new String[options.getFetchSourceIncludes().size()]); String[] excludes = options.getFetchSourceExcludes().toArray(new String[options.getFetchSourceExcludes().size()]); builder.setFetchSource(includes, excludes);