Need help in writing a multi condition Query

Hi Team,
Need help in writing JAVA API query.
These are my elastic documents.

{
	"number":1,
	"effective_date":"2024-10-01T00:00:00.000Z"
}
{
	"number":2,
	"effective_date":"2024-10-02T00:00:00.000Z"
}
{
	"number":3,
	"effective_date":"2024-10-03T00:00:00.000Z"
}
{
	"number":4,
	"effective_date":"2024-10-04T00:00:00.000Z"
}

Now I have 2 conditions

  1. List numbers = List.of(2,3,4);
    Search with numbers list.
  2. Apply DateRange gte on top of it "2024-10-03T00:00:00.000Z"

With this criteria
I should get 3rd and 4th documents in result.
Result size should be 2.

Thanks

In your example, with this list of 2, 3, 4, only the daterange really matters.

I'd suggest a use-case with 2, 3 as values from the list and the same date range, which should give only the doc 3.

Something like:

void boolQuery() throws IOException {
    client.index(ir -> ir.index(indexName).id("1").withJson(new StringReader("""
            {
                "number":1,
                "effective_date":"2024-10-01T00:00:00.000Z"
            }""")));
    client.index(ir -> ir.index(indexName).id("2").withJson(new StringReader("""
            {
                "number":2,
                "effective_date":"2024-10-02T00:00:00.000Z"
            }""")));
    client.index(ir -> ir.index(indexName).id("3").withJson(new StringReader("""
            {
                "number":3,
                "effective_date":"2024-10-03T00:00:00.000Z"
            }""")));
    client.index(ir -> ir.index(indexName).id("4").withJson(new StringReader("""
            {
                "number":4,
                "effective_date":"2024-10-04T00:00:00.000Z"
            }""")));
    client.indices().refresh(rr -> rr.index(indexName));
    SearchResponse<Void> response = client.search(sr -> sr
                    .index(indexName)
                    .query(q -> q.bool(bq -> bq
                            .filter(fq -> fq.terms(tq -> tq.field("number")
                                    .terms(t -> t.value(List.of(
                                            FieldValue.of("2"), 
                                            FieldValue.of("3"))))))
                            .filter(fq -> fq
                                    .range(rq -> rq.date(drq -> drq
                                            .field("effective_date")
                                            .gte("2024-10-03T00:00:00.000Z"))))
                    ))
            , Void.class);
    assertNotNull(response.hits().total());
    assertEquals(1, response.hits().total().value());
    assertEquals("3", response.hits().hits().get(0).id());
}

I documented it here:

Hi there,
I want pass list to the query.
looking for that query

List.of seems to be a List to me. What do you mean?

I want to use numbers in the query. I dont want to expand it.

You mean that you don't want to convert a List of numbers to a List of FieldValue?

Yes. I dont want to expand my list.

Convert is okay, but I dont want to expand my list. I have a big list.

I don't understand. Anyway, I don't have any other idea.

List.of(FieldValue.of("2"), FieldValue.of("3"))
I have a list of 100 numbers.
I cant expand like this for 100 numbers.
Can I pass it as list?

I guess you can easily write a method which does that