Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a range query #51

Closed
mindscratch opened this issue Dec 6, 2021 · 2 comments
Closed

How to create a range query #51

mindscratch opened this issue Dec 6, 2021 · 2 comments

Comments

@mindscratch
Copy link

I create a client to perform a search and most of the builder types build a type of query except for range:

client.search({ s ->
   s.index("myindex")
     .query { q -> q.range(someJsonValue) }

Most of the functions on the "query builder" allow something to be built, where range wants a JsonValue, how do we build that JsonValue?

@mindscratch
Copy link
Author

Looks like it's coming in the next version :)

@swallez
Copy link
Member

swallez commented Dec 8, 2021

@mindscratch since 7.16.0 release was so close I wanted to wait until it was actually out, but you figured out earlier :-)

Here's what it looks like with 7.16:

SearchRequest req = SearchRequest.of(b -> b
    .query(q -> q
        .range(r -> r
            .field("field-name")
            .gt(JsonData.of("bar"))
            .lt(JsonData.of("foo"))
        )
    )
);

The JsonData type is some arbitrary data that can be translated to JSON, as there are may ways to express range bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants