【问题标题】:Elasticsearch client NEST not storing timestampElasticsearch 客户端 NEST 不存储时间戳
【发布时间】:2014-10-14 12:49:25
【问题描述】:

我正在尝试创建 Elasticsearch 索引并使用 NEST 为文档编制索引。

我通过Marvel Sense仪表盘查询结果,可以看到索引已经创建,可以看到我的文档也已经创建,但是文档上没有_timestamp字段。

当我尝试通过我的 Kibana 仪表板查看索引和文档时出现问题,因为它找不到与过滤器一起使用的时间戳。

我创建的索引如下:

var createIndexResult = _elasticClient.CreateIndex(errorIndex, c => c
                .NumberOfReplicas(0)
                .NumberOfShards(1)
                .Settings(s => s
                    .Add("merge.policy.merge_factor", "10")
                    .Add("search.slowlog.threshold.fetch.warn", "1s"))
                .AddMapping<ElmahErrorDocument>(m => m
                    .TimestampField(f => f
                        .Enabled()
                    )

                )
            );

我正在按如下方式索引我的文档:

var indexResponse = _elasticClient.Index(errorDocument, i => i
                                .Timestamp(timestamp.ToString("o"))
                                .Type("elmah")
                                .Id(errorDocument.Id)
                            );

但由于某种原因,我在查询结果时看不到 _timestamp 字段。

使用 NEST 索引文档时如何获取要存储的时间戳?

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    您无法在查询中获取 _timestamp 字段。也许你试试这个

    elasticClient.CreateIndex("YourIndexName", c => c.AddMapping<yourClass>(m => m                    
                    .MapFromAttributes()
                    .TimestampField(t => t
                    .Enabled(true)
                    .Path(o => o.time)                                   
                    )
                 )
              );
    

    它将使用您文档的属性(在我的 cas 中为 time,格式为 DateTime)作为 _timestamp 值。

    你可以查看

     curl -X GET 'http://someip:9200/yourIndex/_mapping?pretty=true'
    

    它应该输出类似这样的东西

    {
    "yourIndex" : {
    "mappings" : {
      "index" : {
        "_timestamp" : {
          "enabled" : true,
          "path" : "time"
        },
        "properties" : {          
          "time" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },          
        }
      }
    }    
    

    在 Kibana 中,您必须为时间戳使用 time 属性。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2013-03-31
      • 2020-12-22
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多