use of org.opensearch.client.json.jackson.JacksonJsonpMapper 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);
}
}
use of org.opensearch.client.json.jackson.JacksonJsonpMapper in project opensearch-java by opensearch-project.
the class JsonpMapperTest method testJacksonCustomMapper.
@Test
public void testJacksonCustomMapper() {
ObjectMapper jkMapper = new ObjectMapper();
jkMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
jkMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JacksonJsonpMapper mapper = new JacksonJsonpMapper(jkMapper);
String json = "{\"children\":[{\"double_value\":3.2,\"int_value\":2}],\"double_value\":2.1,\"int_value\":1," + "\"string_value\":\"foo\"}";
testSerialize(mapper, json);
testDeserialize(mapper, json);
}
use of org.opensearch.client.json.jackson.JacksonJsonpMapper in project opensearch-java by opensearch-project.
the class JsonpMapperTest method testJackson.
@Test
public void testJackson() {
JacksonJsonpMapper mapper = new JacksonJsonpMapper();
testSerialize(new JacksonJsonpMapper(), json);
testDeserialize(new JacksonJsonpMapper(), json);
}
use of org.opensearch.client.json.jackson.JacksonJsonpMapper 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
}
use of org.opensearch.client.json.jackson.JacksonJsonpMapper 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
}
Aggregations