use of co.elastic.clients.elasticsearch._types.query_dsl.Query in project opensearch-java by opensearch-project.
the class ApiConventionsTest method variantCreation.
@Test
public void variantCreation() {
// tag::variant-creation
Query query = new Query.Builder().term(t -> // <1>
t.field(// <2>
"name").value(v -> v.stringValue("foo"))).build();
// end::variant-creation
// tag::variant-navigation
assertEquals("foo", query.term().value().stringValue());
// tag::variant-kind
if (query.isTerm()) {
// <1>
doSomething(query.term());
}
switch(// <2>
query._kind()) {
case Term:
doSomething(query.term());
break;
case Intervals:
doSomething(query.intervals());
break;
default:
// <3>
doSomething(query._kind(), query._get());
}
// end::variant-kind
}
use of co.elastic.clients.elasticsearch._types.query_dsl.Query in project opensearch-java by opensearch-project.
the class VariantsTest method testBuilders.
@Test
public void testBuilders() {
Query q = new Query(QueryBuilders.exists().field("foo").build());
assertEquals("{\"exists\":{\"field\":\"foo\"}}", toJson(q));
}
Aggregations