0

Hi I am trying to create a query with elastic search :

<dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>8.5.3</version>
</dependency>

I need the query to select multiple files based on values:

query = MatchQuery.of(m -> m
                        .field("fileType")
                        .query("EXP", "WAIT_EXP")
                    )._toQuery();

But this is giving me an syntax error. The query only gets 1 value. I need the get files with fileType both exp or wait_exp.

I read the documentation at here https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html but cant find anything helpfull.

1 Answer 1

1

You can use bool query. Also you can check this thread.

SearchRequest request = new SearchRequest("your_index");

BoolQuery boolQuery = new BoolQuery();

boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("EXP")));
boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("WAIT_EXP")));

request.query(boolQuery);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.