0

I am writing some queries in my ElasticSearch project that can be filtered by Date. I have written them like this:

var searchResponse = client.Search<mdl.Event>(s => s
                    .Query(q => q
                        .QueryString(qs => qs
                            .Query(search.Space))
                        && q
                        .DateRange(r => r
                            .Field(f => f.CreatedTimeStamp)
                            .GreaterThanOrEquals(search.From)
                            .LessThanOrEquals(search.To))));

However, search.From and search.To are optional inputs, so they might turn out to be null. In the event that they are null, does this break the query? Or will it continue as if the DateRange part of the query is not included?

1 Answer 1

1

Nest queries are condition less. If input is determined to be null or empty string then the query will be omitted from the request.

So you don't need to check whether each filter property is null , NEST will perform this filtering by default.

In your case if search.From and search.To are null then range check will be removed from final query

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.