Date Range Query Usage

edit

Fluent DSL example

edit
q
.DateRange(c => c
    .Name("named_query")
    .Boost(1.1)
    .Field(p => p.LastActivity)
    .GreaterThanOrEquals(DateMath.Now.Subtract("1y").RoundTo(DateMathTimeUnit.Month))
    .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 = "lastActivity",
    GreaterThanOrEqualTo = DateMath.Now.Subtract("1y").RoundTo(DateMathTimeUnit.Month),
    LessThanOrEqualTo = DateMath.Now,
    TimeZone = "+01:00",
    Format = "dd/MM/yyyy||yyyy"
}

Example json output.

{
  "range": {
    "lastActivity": {
      "_name": "named_query",
      "boost": 1.1,
      "format": "dd/MM/yyyy||yyyy",
      "gte": "now-1y/M",
      "lte": "now",
      "time_zone": "+01:00"
    }
  }
}