I have a function which does a search on documents in a time interval, based on a boolean flag, the NEST query would be different to use LessThanOrEqual in if statment and LessThan in else statement.
public IEnumerable<Book> GetBooks(DateTime startTime, DateTime endTime, string author, bool includeEnd)
{
var readRecords;
if (includeEnd){
readRecords = elastic.Search<Book>(s => s.Index(IndexName)
.Query(q => q.Term(book => book.Author, author) &&
q.DateRange(i => i.Field(book => book.Author)
.GreaterThanOrEquals(startTime)
.LessThanOrEquals(endTime)))).Documents.ToArray();
}
else{
readRecords = elastic.Search<Book>(s => s.Index(IndexName)
.Query(q => q.Term(book => book.Author, author) &&
q.DateRange(i => i.Field(book => book.Author)
.GreaterThanOrEquals(startTime)
.LessThan(endTime)))).Documents.ToArray();
}
return readRecords;
}
How can I make this NEST query dynamic using the boolean flag "includeEnd" so that I do not need to use the if statement?