/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(String indexName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); Map<String, Object> map = getMap(response); return map; }
@Override public GetResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { final GetResponse response = client.prepareGet(indexKey, table, key).execute().actionGet();
public Status update(String table, String key, Map<String, ByteIterator> values) { try { final GetResponse response = client.prepareGet(indexKey, table, key).execute().actionGet();
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareGet(INDEX_TYPE_FAKE, "ruleKey").execute(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous"); } }
.setOperationThreaded(false) .setFields(new String[]{}) .execute() .actionGet(); return getResponse.isExists();
@Override public void execute(Tuple tuple) { try { String index = mapper.getIndex(tuple); String type = mapper.getType(tuple); String id = mapper.getId(tuple); GetResponse response = client.prepareGet(index, type, id).execute() .actionGet(); collector.emit(esOutputDeclarer.getValues(response.getSource())); collector.ack(tuple); } catch (Exception e) { collector.fail(tuple); } }
getRequestBuilder.putHeader("Authorization", authToken); final GetResponse getResponse = getRequestBuilder.execute().actionGet();
final GetResponse getResponse = getRequestBuilder.execute().actionGet();
/** * Read a json document from the search index for a given id. * Elasticsearch reads the '_source' field and parses the content as json. * * @param id * the unique identifier of a document * @return the document as json, matched on a Map<String, Object> object instance */ public Map<String, Object> readMap(final String indexName, final String typeName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, typeName, id).execute().actionGet(); Map<String, Object> map = getMap(response); return map; }
/** * Read a document from the search index for a given id. * This is the cheapest document retrieval from the '_source' field because * elasticsearch does not do any json transformation or parsing. We * get simply the text from the '_source' field. This might be useful to * make a dump from the index content. * * @param id * the unique identifier of a document * @return the document as source text */ public byte[] readSource(String indexName, final String id) { GetResponse response = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); return response.getSourceAsBytes(); }
/** * Get the type name of a document or null if the document does not exist. * This is a replacement of the exist() method which does exactly the same as exist() * but is able to return the type name in case that exist is successful. * Please read the comment to exist() for details. * @param indexName * the name of the index * @param id * the unique identifier of a document * @return the type name of the document if it exists, null otherwise */ public String getType(String indexName, final String id) { GetResponse getResponse = elasticsearchClient.prepareGet(indexName, null, id).execute().actionGet(); return getResponse.isExists() ? getResponse.getType() : null; }
@Override public Record findRecordById(String id) { GetResponse getResponse = client .prepareGet(this.indexName, this.indexType, id).execute() .actionGet(); return this .readFromSource(getResponse.getId(), getResponse.getSource()); }
.prepareGet(indexName, typeName, id) .setOperationThreaded(false) .execute() .actionGet(); return getResponse.isExists();
.setOperationThreaded(false).execute().get();
private static void checkIndicesWithDocument(List<GetRequestBuilder> indexes, Map<String, Object> expectedDataOfDocument) { for (GetRequestBuilder getRequestBuilder : indexes) { GetResponse dataOfDocumentResponse = getRequestBuilder.execute().actionGet(); checkExistenceOfDocument(getRequestBuilder, dataOfDocumentResponse); checkDocumentEquality(expectedDataOfDocument, getRequestBuilder, dataOfDocumentResponse); } }
private static void checkIndicesWithDocument(List<GetRequestBuilder> indexes, Map<String, Object> expectedDataOfDocument) throws Error { for (GetRequestBuilder getRequestBuilder : indexes) { GetResponse dataOfDocumentResponse = getRequestBuilder.execute().actionGet(); checkExistanceOfDocument(getRequestBuilder, dataOfDocumentResponse); checkDocumentEquality(expectedDataOfDocument, getRequestBuilder, dataOfDocumentResponse); } }
public ElasticsearchSample get(Object key) { GetResponse getResponse = client.prepareGet(index, type, String.valueOf(key)).execute().actionGet(); Map<String, Object> map = getResponse.getSource(); if (map == null) { return null; } else { map.put(ID, getResponse.getId()); return new ElasticsearchSample(this, map); } }
/** * {@inheritDoc} */ @Override public ElasticSearchDoc get(final String type, final String id, final String index) { ElasticSearchDoc result = null; final GetResponse response = client.prepareGet(index, type, id).execute().actionGet(esCallTimeout); if (response.isExists()) { result = parse(response); } return result; }
@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(); } }