Search in sources :

Example 11 with Query

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
}
Also used : OpenSearchAsyncClient(org.opensearch.client.opensearch.OpenSearchAsyncClient) Arrays(java.util.Arrays) Aggregation(org.opensearch.client.opensearch._types.aggregations.Aggregation) Alias(org.opensearch.client.opensearch.indices.Alias) Query(org.opensearch.client.opensearch._types.query_dsl.Query) CreateIndexRequest(org.opensearch.client.opensearch.indices.CreateIndexRequest) LogManager(java.util.logging.LogManager) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Test(org.junit.Test) HashMap(java.util.HashMap) CreateIndexResponse(org.opensearch.client.opensearch.indices.CreateIndexResponse) Logger(java.util.logging.Logger) SearchResponse(org.opensearch.client.opensearch.core.SearchResponse) OpenSearchTransport(org.opensearch.client.transport.OpenSearchTransport) TransportException(org.opensearch.client.transport.TransportException) List(java.util.List) SearchRequest(org.opensearch.client.opensearch.core.SearchRequest) NodeStatistics(org.opensearch.client.opensearch._types.NodeStatistics) SortOrder(org.opensearch.client.opensearch._types.SortOrder) ApiTypeHelper(org.opensearch.client.util.ApiTypeHelper) Map(java.util.Map) Assert(org.junit.Assert) Query(org.opensearch.client.opensearch._types.query_dsl.Query) Test(org.junit.Test)

Example 12 with Query

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));
}
Also used : Query(org.opensearch.client.opensearch._types.query_dsl.Query) Test(org.junit.Test)

Aggregations

Query (co.elastic.clients.elasticsearch._types.query_dsl.Query)5 Test (org.junit.Test)5 Query (org.opensearch.client.opensearch._types.query_dsl.Query)5 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 ArrayList (java.util.ArrayList)3 ElasticsearchException (co.elastic.clients.elasticsearch._types.ElasticsearchException)2 ErrorCause (co.elastic.clients.elasticsearch._types.ErrorCause)2 Result (co.elastic.clients.elasticsearch._types.Result)2 Time (co.elastic.clients.elasticsearch._types.Time)2 BulkResponse (co.elastic.clients.elasticsearch.core.BulkResponse)2 DeleteResponse (co.elastic.clients.elasticsearch.core.DeleteResponse)2 GetResponse (co.elastic.clients.elasticsearch.core.GetResponse)2 BulkOperation (co.elastic.clients.elasticsearch.core.bulk.BulkOperation)2 BulkResponseItem (co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem)2 CompletionSuggestOption (co.elastic.clients.elasticsearch.core.search.CompletionSuggestOption)2 Hit (co.elastic.clients.elasticsearch.core.search.Hit)2 Suggester (co.elastic.clients.elasticsearch.core.search.Suggester)2 AnalyzeResponse (co.elastic.clients.elasticsearch.indices.AnalyzeResponse)2