Attempt filtered data by range using timestamp field. Query is beelow:
var scanResults = await _elasticClient.SearchAsync<OemCatalogModel>(s => s.Index(indexName)
.Source(sf => sf
.Includes(i => i
.Fields(
f => f.Event,
f => f.MemberId,
f => f.IsInternalUser,
f => f.IndexName,
f => f.IsMobile,
f => f.VinNumber,
f => f.Timestamp
)
)
)
.Query(q => q.Range(p => p.Field<Timestamp>(t=>t.Timestamp)
.GreaterThanOrEquals(sd)
.LessThanOrEquals(ed)
))
.Size(10000).Scroll("60s"));
startDate and endDate geted from DatePicker as DateTimeOffset and init sd and ed like beelow:
var sd = startDate.Value.ToUnixTimeSeconds();
var ed = endDate.Value.ToUnixTimeSeconds();
Timestamp field looks following in mapping model
[Date(Name = "timestamp")]
public Int64 Timestamp { get; set; }
This query raised "parse_exception" exception:
"reason" : {
"type" : "parse_exception",
"reason" : "failed to parse date field [1.6540308E9] with format [epoch_second]: [failed to parse date field [1.6540308E9] with format [epoch_second]]",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "failed to parse date field [1.6540308E9] with format [epoch_second]",
"caused_by" : {
"type" : "date_time_parse_exception",
"reason" : "date_time_parse_exception: Failed to parse with all enclosed parsers"
}
}
}
ElasticSearch query that generated by NEST looks following:
{"query":{"range":{"timestamp":{"gte":1654030800.0,"lte":1654203599.0}}},"size":10000,"_source":{"includes":["event","member_id","is_internal_user","indexName","is_mobile","vin_number","timestamp"]}}
This filter not working because to range arguments added .0. I checked this witout .0 and it is works. For example result for _source looks like:
"_source" : {
"member_id" : 69500,
"is_mobile" : false,
"event" : "close_unit_card",
"is_internal_user" : false,
"timestamp" : 1654066236
}
How mapped correctly the range filter with timestamp? Maybee I must using DataRange? If yes, how cast sd and ed to timestamp that using in ElasticSearch?
Also trying to do the following but getting a different exception:
Query looks like:
.Query(q => q.DateRange(p => p.Field(t=>t.Timestamp)
.GreaterThanOrEquals(DateTime.Parse(startDate.Value.ToString()))
.LessThanOrEquals(DateTime.Parse(endDate.Value.ToString()))))
Rise following exception:
"reason" : {
"type" : "parse_exception",
"reason" : "failed to parse date field [2022-05-31T21:00:00Z] with format [epoch_second]: [failed to parse date field [2022-05-31T21:00:00Z] with format [epoch_second]]",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "failed to parse date field [2022-05-31T21:00:00Z] with format [epoch_second]",
"caused_by" : {
"type" : "date_time_parse_exception",
"reason" : "date_time_parse_exception: Failed to parse with all enclosed parsers"
}
}
}
.GreaterThanOrEquals(DateTime.Parse(sd)) .LessThanOrEquals(DateTime.Parse(ed))and see if it is working or not.RangetoDataRangebutDateTime.Parsecan't parseInt64. Also rise another exception if pass DateTime in DataRange because ElasticSearch using Timestamp...