Skip to content

Date Range Filter not serializing Format  #2208

@matt-lethargic

Description

@matt-lethargic

NEST/Elasticsearch.Net version_: 1.7.2
_Elasticsearch version*: 1.7.5

Description of the problem including expected versus actual behavior:

This code

return new FunctionScoreFunction<GroupListSearchDataContract>()
                    .Weight(weight)
                    .Filter(fi => fi
                        .Bool(b => b
                            .Should(
                                s => s.Range(r => r.OnField(f => f.RoleCriteria.TargetMoveIn)
                                    .GreaterOrEquals(earliestDate)
                                    .LowerOrEquals(farthestDate)
                                    .Format("yyyy-MM-dd'T'HH:mm:ss.SSS"))
                            )));

Produces this json

            {
              "filter": {
                "bool": {
                  "should": [
                    {
                      "range": {
                        "roleCriteria.targetMoveIn": {
                          "lte": "2016-09-02T00:00:00.000",
                          "gte": "2016-07-02T00:00:00.000"
                        }
                      }
                    }
                  ]
                }
              },
              "weight": 1
            }

The mapping for the date field is

.Date(d => d.Name(n => n.TargetMoveIn).Format("yyyy-MM-dd'T'HH:mm:ss"))

Notice there is no "format" property in the json produced and therefore ES throws an exception. If I manually added the format and directly query ES it works fine.
Let me know if you need more information.

FYI My workaround is this

return new FunctionScoreFunction<GroupListSearchDataContract>()
                    .Weight(weight)
                    .Filter(fi => fi
                        .Bool(b => b
                            .Should(
                                s => s.Range(r => r.OnField(f => f.RoleCriteria.TargetMoveIn)
                                    .GreaterOrEquals(earliestDate, "yyyy-MM-dd'T'HH:mm:ss")
                                    .LowerOrEquals(farthestDate, "yyyy-MM-dd'T'HH:mm:ss")
                                )
                            )));

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