Date Range Query Usage

edit

Fluent DSL example

edit
q
.DateRange(c => c
    .Name("named_query")
    .Boost(1.1)
    .Field(p => p.Description)
    .GreaterThan(FixedDate)
    .GreaterThanOrEquals(DateMath.Anchored(FixedDate).RoundTo(DateMathTimeUnit.Month))
    .LessThan("01/01/2012")
    .LessThanOrEquals(DateMath.Now)
    .Format("dd/MM/yyyy||yyyy")
    .TimeZone("+01:00")
)

Object Initializer syntax example

edit
new DateRangeQuery
{
    Name = "named_query",
    Boost = 1.1,
    Field = "description",
    GreaterThan = FixedDate,
    GreaterThanOrEqualTo = DateMath.Anchored(FixedDate).RoundTo(DateMathTimeUnit.Month),
    LessThan = "01/01/2012",
    LessThanOrEqualTo = DateMath.Now,
    TimeZone = "+01:00",
    Format = "dd/MM/yyyy||yyyy"
}

Example json output.

{
  "range": {
    "description": {
      "_name": "named_query",
      "boost": 1.1,
      "format": "dd/MM/yyyy||yyyy",
      "gt": "2015-06-06T12:01:02.123",
      "gte": "2015-06-06T12:01:02.123||/M",
      "lt": "01/01/2012",
      "lte": "now",
      "time_zone": "+01:00"
    }
  }
}