use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project spring-boot by spring-projects.
the class ElasticsearchRestClientAutoConfigurationIntegrationTests method restClientCanQueryElasticsearchNode.
@Test
@SuppressWarnings("deprecation")
void restClientCanQueryElasticsearchNode() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(), "spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s").run((context) -> {
org.elasticsearch.client.RestHighLevelClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class);
Map<String, String> source = new HashMap<>();
source.put("a", "alpha");
source.put("b", "bravo");
IndexRequest index = new IndexRequest("test").id("1").source(source);
client.index(index, RequestOptions.DEFAULT);
GetRequest getRequest = new GetRequest("test").id("1");
assertThat(client.get(getRequest, RequestOptions.DEFAULT).isExists()).isTrue();
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project gora by apache.
the class ElasticsearchStore method get.
@Override
public T get(K key, String[] fields) throws GoraException {
String[] requestedFields = getFieldsToQuery(fields);
List<String> documentFields = new ArrayList<>();
for (String requestedField : requestedFields) {
documentFields.add(elasticsearchMapping.getFields().get(requestedField).getName());
}
try {
// Prepare the Elasticsearch request
GetRequest getRequest = new GetRequest(elasticsearchMapping.getIndexName(), (String) key);
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
if (getResponse.isExists()) {
Map<String, Object> sourceMap = getResponse.getSourceAsMap();
// Map of field's name and its value from the Document
Map<String, Object> fieldsAndValues = new HashMap<>();
for (String field : documentFields) {
fieldsAndValues.put(field, sourceMap.get(field));
}
// Build the corresponding persistent
return newInstance(fieldsAndValues, requestedFields);
} else {
return null;
}
} catch (IOException ex) {
throw new GoraException(ex);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project sonarqube by SonarSource.
the class EsRequestDetailsTest method should_format_GetRequest.
@Test
public void should_format_GetRequest() {
GetRequest request = new GetRequest().index("index-1").type("type-1").id("id-1");
assertThat(EsRequestDetails.computeDetailsAsString(request)).isEqualTo("ES get request for key 'id-1' on index 'index-1' on type 'type-1'");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project datashare by ICIJ.
the class ElasticsearchIndexer method get.
@Override
public <T extends Entity> T get(String indexName, String id, String root) {
String type = null;
try {
final GetRequest req = new GetRequest(indexName, id).routing(root);
final GetResponse resp = client.get(req, RequestOptions.DEFAULT);
if (resp.isExists()) {
Map<String, Object> sourceAsMap = resp.getSourceAsMap();
sourceAsMap.put("rootDocument", ofNullable(resp.getFields().get("_routing")).orElse(new DocumentField("_routing", Collections.singletonList(id))).getValues().get(0));
type = (String) sourceAsMap.get(esCfg.docTypeField);
Class<T> tClass = (Class<T>) Class.forName("org.icij.datashare.text." + type);
return JsonObjectMapper.getObject(id, sourceAsMap, tClass);
}
} catch (IOException e) {
LOGGER.error("Failed to get entity " + id + " in index " + indexName, e);
} catch (ClassNotFoundException e) {
LOGGER.error("no entity for type " + type);
}
return null;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project datashare by ICIJ.
the class ElasticsearchSpewer method isDuplicate.
private boolean isDuplicate(String docId) throws IOException {
GetRequest getRequest = new GetRequest(indexName, docId);
getRequest.fetchSourceContext(new FetchSourceContext(false));
getRequest.storedFields("_none_");
return client.exists(getRequest, RequestOptions.DEFAULT);
}
Aggregations