gpt4 book ai didi

c# - 将时间戳记添加到ElasticSearch-Nest 2.0中添加的每个文档中

转载 作者:行者123 更新时间:2023-12-03 00:59:50 26 4
gpt4 key购买 nike

如何确保在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")
  • 使用NEST和C#如何确保索引的每个文档都带有时间戳?
  • 如何查询早于一个小时前的<MyDoc>类型的所有文档?

  • 我发现了这个: Adding Timestamp to each document added in ElasticSearch
    但是它没有告诉我如何使用NEST进行此操作

    我已经尝试过了,但是查看结果的时间戳为null并返回索引中的所有文档:
            var test =
    elasticClient.Search<MyDoc>(
    s => s.Query(q => q.DateRange(x => x.LessThan(DateTime.Now.AddHours(-1)))));

    最佳答案

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

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

    关于c# - 将时间戳记添加到ElasticSearch-Nest 2.0中添加的每个文档中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39535422/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com