Skip to content

Incorrect query after using DateTime.MinValue in the DateRange filter #3505

Closed
@IvanSorokin

Description

@IvanSorokin

NEST/Elasticsearch.Net version: 6.4.0

Elasticsearch version: 6.5.1

Description of the problem including expected versus actual behavior:
I am using filter for counting documents like this

private static Func<QueryContainerDescriptor<ISearchableNotification>, QueryContainer> IndexedDateFromFilter(SearchQuery query)
{
    if (query.IndexedDateFrom.HasValue)
        return filter => filter.DateRange(rf => rf.Field(nm => nm.IndexedDateTime)
                                                  .GreaterThanOrEquals(query.IndexedDateFrom));
     return null;
}

IndexedDateFrom's type is [DateTime?]. When IndexedDateFrom equals DateTime.MinValue everything crashes with exception

org.elasticsearch.ElasticsearchParseException: failed to parse date field [] with format [strict_date_optional_time||epoch_millis]

because NEST translates C# code into this (part of the query I got from DebugInformation)

{
                "range": {
                  "indexedDateTime": {
                    "gte": ""
                  }
                }
}

If I use DateTime.MinValue.AddDays(1) instead of DateTime.MinValue everything works fine. It looks like a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions