【问题标题】:Add Timestamp to each document added in ElasticSearch - Nest 2.0为 ElasticSearch 中添加的每个文档添加时间戳 - Nest 2.0
【发布时间】:2016-09-16 15:43:04
【问题描述】:

如何确保在 elasticsearch 中编入索引的每个文档都有时间戳?

        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# 如何确保我索引的每个文档都有时间戳?
  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)))));

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    您可以启用 _timestamp,但不推荐使用 _timestamp。不再使用它,只需在数据对象中定义日期属性并显式设置即可

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

    【讨论】:

      猜你喜欢
      • 2015-02-16
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      相关资源
      最近更新 更多