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.

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
Levent
  • 1

1 Answers1

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);
Musab Dogan
  • 1,811
  • 1
  • 6
  • 8