Reputation: 21328
How can I make sure each document indexed in elasticsearch gets timestamped?
node = new Uri("http://localhost:9201);
settings =
new ConnectionSettings(node).DefaultIndex("mytestindex");
elasticClient = new ElasticClient(settings);
// Then I do
elasticClient.Index(connections, idx => idx.Id("1")
<MyDoc>
with older than an hour ago?I found this: Adding Timestamp to each document added in ElasticSearch however it doesn't show me how to do this with NEST
I've tried this, however looking at the result timestamp is null and it returns all documents in index:
var test =
elasticClient.Search<MyDoc>(
s => s.Query(q => q.DateRange(x => x.LessThan(DateTime.Now.AddHours(-1)))));
Upvotes: 0
Views: 1434
Reputation: 406
You can enable _timestamp but _timestamp is deprecated. Don't use it anymore, just define a date properties in your data object and set it explicitly
await client.MapAsync<Blog>(m => m.TimestampField(t => t.Enabled(true)));
Upvotes: 2