Struct elastic_types::date::DateExpr [] [src]

pub struct DateExpr<TFormat> { /* fields omitted */ }

A date math expression.

Date math expressions start from an anchor date, like the literal now or 2017-05-06 and apply math operations to produce a new date value.

Examples

A date expression for now plus 2 days:

let expr: DateExpr<BasicDateTime> = DateExpr::now().add_days(2);

Which serialises to:

"now+2d"

A date expression using a concrete date value plus 2 days:

let expr: DateExpr<BasicDateTime> = DateExpr::value(DateValue::now()).add_days(2);

Which serialises to:

"20150301T145500.000Z||+2d"

Methods

impl<TFormat> DateExpr<TFormat> where
    TFormat: DateFormat
[src]

[src]

Create a new date expression for now.

This value is different from Date::now() because it doesn't calculate the current date from the system clock. It serialises to the literal string "now", which is interpreted by Elasticsearch when indexing.

[src]

Create a new date expression from a concrete date value.

If the input is a DateValue, then it'll use any format specified on the DateExpr. If the input is a Date or chrono::DateTime, then the format on its mapping must match the format expected by the DateExpr.

Examples

Create a date expression from a chrono::DateTime:

let date = DateValue::now();

// The format annotation `EpochMillis` is required
let expr: DateExpr<EpochMillis> = DateExpr::value(date);

Create a date expression from a Date:

let date: Date<DefaultDateMapping<EpochMillis>> = Date::now();

// The format `EpochMillis` is inferred
let expr = DateExpr::value(date);

Attempting to create a date expression from a Date with a different format will fail to compile:

let date: Date<DefaultDateMapping<BasicDateTime>> = Date::now();

// Error: expected struct `EpochMillis`, found struct `BasicDateTime`
let expr: DateExpr<EpochMillis> = DateExpr::value(date);

This is to ensure formats aren't silently converted when they shouldn't be, leading to runtime errors in Elasticsearch. Convert the date into a DateValue first:

let date: Date<DefaultDateMapping<BasicDateTime>> = Date::now();

let expr: DateExpr<EpochMillis> = DateExpr::value(DateValue::from(date));

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

[src]

Add to the anchored date.

[src]

Subtract from the anchored date.

[src]

Round the anchored date.

Trait Implementations

impl<TFormat: Debug> Debug for DateExpr<TFormat>
[src]

[src]

Formats the value using the given formatter.

impl<TFormat: Clone> Clone for DateExpr<TFormat>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<TFormat: PartialEq> PartialEq for DateExpr<TFormat>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<TFormat> Display for DateExpr<TFormat> where
    TFormat: DateFormat
[src]

[src]

Formats the value using the given formatter. Read more

impl<TFormat> Serialize for DateExpr<TFormat> where
    TFormat: DateFormat
[src]

[src]

Serialize this value into the given Serde serializer. Read more