DateRange if DateTime Field not null?


(Mehmet KURT) #1

Hi everybody,

My table columns are not always null! Therefore, I need to check when querying the date range.

I'm passing the Linq question below. How can I do that?

query = query.where(p => 
        (!p.markasnewstartdatetimeutc.hasvalue || p.markasnewstartdatetimeutc.value < nowutc) &&
        (!p.markasnewenddatetimeutc.hasvalue || p.markasnewenddatetimeutc.value > nowutc));

Sample Usage!

List<Func<QueryContainerDescriptor<Product>, QueryContainer>>();

var nowUtc = DateTime.UtcNow;
            if (markedAsNewOnly)
            {
                filters.Add(fq => fq.Terms(t => t.Field(f => f.MarkAsNew).Terms(true)));
                filters.Add(fq => fq.Exists())

                filters.Add(fq => fq.DateRange(dr =>
                {
                    //?????
                }));
            }

  var searchResponse = client.Search<Product>(s => s
                .Index("product")
                .Query(q => q.Bool(b => b.Filter(filters)))
            );

(Mehmet KURT) #2

help me!


(David Pilato) #3

Read this and specifically the "Also be patient" part.


(Mehmet KURT) #4

I am still waiting, it is very difficult!


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.