Search in sources :

Example 6 with GetRequest

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")));
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 7 with GetRequest

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);
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) GetRequest(org.elasticsearch.action.get.GetRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException)

Example 8 with GetRequest

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;
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 9 with GetRequest

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));
    }
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 10 with GetRequest

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();
    });
}
Also used : ReactiveElasticsearchClient(org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient) GetResult(org.elasticsearch.index.get.GetResult) HashMap(java.util.HashMap) GetRequest(org.elasticsearch.action.get.GetRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GetRequest (org.elasticsearch.action.get.GetRequest)45 GetResponse (org.elasticsearch.action.get.GetResponse)29 Test (org.junit.Test)14 IOException (java.io.IOException)13 IndexRequest (org.elasticsearch.action.index.IndexRequest)9 HashMap (java.util.HashMap)7 TikaDocument (org.icij.extract.document.TikaDocument)7 FetchSourceContext (org.elasticsearch.search.fetch.subphase.FetchSourceContext)6 ArrayList (java.util.ArrayList)5 DocumentFactory (org.icij.extract.document.DocumentFactory)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ParsingReader (org.apache.tika.parser.ParsingReader)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)4 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)4 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)4 PathIdentifier (org.icij.extract.document.PathIdentifier)4 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)3 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)3