Search in sources :

Example 1 with OpenSearchTransport

use of org.opensearch.client.transport.OpenSearchTransport in project opensearch-java by opensearch-project.

the class OpenSearchRestHighLevelClientTestCase method initHighLevelClient.

@Before
public void initHighLevelClient() throws IOException {
    super.initClient();
    if (restHighLevelClient == null) {
        // Create the low-level client
        restClient = client();
        // Create the transport that provides JSON and http services to API clients
        OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
        // Create API client
        restHighLevelClient = new OpenSearchClient(transport);
    }
}
Also used : RestClientTransport(org.opensearch.client.transport.rest_client.RestClientTransport) JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) Before(org.junit.Before)

Example 2 with OpenSearchTransport

use of org.opensearch.client.transport.OpenSearchTransport in project opensearch-java by opensearch-project.

the class ConnectingTest method createClient.

// we don't have a running ES
@Ignore
@Test
public void createClient() throws Exception {
    // tag::create-client
    // Create the low-level client
    RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
    // Create the transport with a Jackson mapper
    OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
    // And create the API client
    OpenSearchClient client = new OpenSearchClient(transport);
    // end::create-client
    // tag::first-request
    SearchResponse<Product> search = client.search(s -> s.index("products").query(q -> q.term(t -> t.field("name").value(v -> v.stringValue("bicycle")))), Product.class);
    for (Hit<Product> hit : search.hits().hits()) {
        processProduct(hit.source());
    }
// end::first-request
}
Also used : JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) Ignore(org.junit.Ignore) RestClientTransport(org.opensearch.client.transport.rest_client.RestClientTransport) RestClient(org.opensearch.client.RestClient) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Test(org.junit.Test) SearchResponse(org.opensearch.client.opensearch.core.SearchResponse) HttpHost(org.apache.http.HttpHost) Hit(org.opensearch.client.opensearch.core.search.Hit) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) RestClientTransport(org.opensearch.client.transport.rest_client.RestClientTransport) HttpHost(org.apache.http.HttpHost) RestClient(org.opensearch.client.RestClient) JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with OpenSearchTransport

use of org.opensearch.client.transport.OpenSearchTransport in project opensearch-java by opensearch-project.

the class MigrateHlrcTest method migrate.

@Test
public void migrate() {
    // tag::migrate
    // Create the low-level client
    RestClientBuilder httpClientBuilder = RestClient.builder(new HttpHost("localhost", 9200));
    // Create the HLRC
    RestHighLevelClient hlrc = new RestHighLevelClient(httpClientBuilder);
    // Create the new Java Client with the same low level client
    OpenSearchTransport transport = new RestClientTransport(hlrc.getLowLevelClient(), new JacksonJsonpMapper());
    OpenSearchClient esClient = new OpenSearchClient(transport);
// hlrc and esClient share the same httpClient
// end::migrate
}
Also used : RestClientTransport(org.opensearch.client.transport.rest_client.RestClientTransport) HttpHost(org.apache.http.HttpHost) JacksonJsonpMapper(org.opensearch.client.json.jackson.JacksonJsonpMapper) RestClientBuilder(org.opensearch.client.RestClientBuilder) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) Test(org.junit.Test)

Aggregations

JacksonJsonpMapper (org.opensearch.client.json.jackson.JacksonJsonpMapper)3 OpenSearchClient (org.opensearch.client.opensearch.OpenSearchClient)3 OpenSearchTransport (org.opensearch.client.transport.OpenSearchTransport)3 RestClientTransport (org.opensearch.client.transport.rest_client.RestClientTransport)3 HttpHost (org.apache.http.HttpHost)2 Test (org.junit.Test)2 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 RestClient (org.opensearch.client.RestClient)1 RestClientBuilder (org.opensearch.client.RestClientBuilder)1 SearchResponse (org.opensearch.client.opensearch.core.SearchResponse)1 Hit (org.opensearch.client.opensearch.core.search.Hit)1