2016-09-16 66 views
0

如何确保elasticsearch中索引的每个文档获取时间戳?将时间戳添加到ElasticSearch中添加的每个文档 - 嵌套2.0

 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") 
  1. 使用NEST和C#我如何确保每个文档我Index获取时间戳?
  2. 如何在一个小时前查询类型为<MyDoc>的所有文档?

我发现这一点:Adding Timestamp to each document added in ElasticSearch 但它不告诉我如何与NEST做到这一点

我试过这个,但是看结果时间戳为空,它返回所有文件的索引:

 var test = 
      elasticClient.Search<MyDoc>(
       s => s.Query(q => q.DateRange(x => x.LessThan(DateTime.Now.AddHours(-1))))); 

回答

2

您可以启用_timestamp,但不建议使用_timestamp。不要再使用它,只需在数据对象中定义日期属性并将其明确设置即可

await client.MapAsync<Blog>(m => m.TimestampField(t => t.Enabled(true)));