use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method getRequestBody.
@Test
public void getRequestBody() throws Exception {
String prefix = createPrefix();
// given
GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
// when
String documentId = template.requestBody("direct:index", new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
GetResponse response = template.requestBody("direct:get", request.id(documentId), GetResponse.class);
// then
assertThat(response, notNullValue());
assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project pancm_project by xuwujing.
the class EsHighLevelRestTest1 method exists.
/**
* 是否存在
*
* @throws IOException
*/
private static void exists() throws IOException {
String type = "_doc";
String index = "test1";
// 唯一编号
String id = "1";
// 创建查询请求
GetRequest getRequest = new GetRequest(index, type, id);
boolean exists = client.exists(getRequest, RequestOptions.DEFAULT);
ActionListener<Boolean> listener = new ActionListener<Boolean>() {
@Override
public void onResponse(Boolean exists) {
System.out.println("==" + exists);
}
@Override
public void onFailure(Exception e) {
System.out.println("失败的原因:" + e.getMessage());
}
};
// 进行异步监听
// client.existsAsync(getRequest, RequestOptions.DEFAULT, listener);
System.out.println("数据是否存在:" + exists);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project pancm_project by xuwujing.
the class IpHandler method queryById.
/**
* @return boolean
* @Author pancm
* @Description 根据id查询
* @Date 2019/3/21
* @Param []
*/
public static Map<String, Object> queryById(String index, String type, String id) throws IOException {
if (index == null || type == null) {
return null;
}
Map<String, Object> map = new HashMap<>();
try {
GetRequest request = new GetRequest();
request.index(index);
request.type(type);
request.id(id);
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
// 如果存在该数据则返回对应的结果
if (getResponse.isExists()) {
map = getResponse.getSourceAsMap();
}
} finally {
if (isAutoClose) {
close();
}
}
return map;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project flink by apache.
the class SourceSinkDataTestKit method verifyProducedSinkData.
/**
* Verify the results in an Elasticsearch index. The results must first be produced into the
* index using a {@link TestElasticsearchSinkFunction};
*
* @param client The client to use to connect to Elasticsearch
* @param index The index to check
*/
public static void verifyProducedSinkData(Client client, String index) {
for (int i = 0; i < NUM_ELEMENTS; i++) {
GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet();
Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfigurationIntegrationTests method restClientCanQueryElasticsearchNode.
@Test
void restClientCanQueryElasticsearchNode() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(), "spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s").run((context) -> {
ReactiveElasticsearchClient client = context.getBean(ReactiveElasticsearchClient.class);
Map<String, String> source = new HashMap<>();
source.put("a", "alpha");
source.put("b", "bravo");
IndexRequest indexRequest = new IndexRequest("foo").id("1").source(source);
GetRequest getRequest = new GetRequest("foo").id("1");
GetResult getResult = client.index(indexRequest).then(client.get(getRequest)).block();
assertThat(getResult).isNotNull();
assertThat(getResult.isExists()).isTrue();
});
}
Aggregations