I am indexing documents using NEST, they dont have a timestamp, is there any way to retrieve/search for the most recent inserted document? or do i have to add a timestamp to my docs when indexing and then sort by that and size(1)?
Yeh, you'll have to add a timestamp to your docs, and can use a simple match_all
query with size = 1
and sort
on your timestamp field.
I am trying to set a Timestamp to documents on Index but the parameter is Nest.Time how can i convert DateTime.Now to Nest.Time TimeSpan?
index_result = elk.Index(c, i => i
.Index("index-" + date)
.Id(asset_tag + "_appliance")
.Timestamp(DateTime.Now)
);
That's probably not the timestamp you want to be using.
What you want to do is add a DateTime
(or DateTimeOffset
) field to your document type, and that's the field you then sort on.
Thanks that worked!
1 Like