elasticsearch - Elasticsearch客户端NEST不存储时间戳

标签 elasticsearch nest

我正在尝试创建一个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为文档建立索引时,如何获取要存储的时间戳?

最佳答案

您无法在查询中获得_timestampfield。也许你试试这个

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属性。

关于elasticsearch - Elasticsearch客户端NEST不存储时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25416972/

相关文章:

jboss - JVM经常崩溃

elasticsearch - ElasticSearch:获取参数不唯一的所有元素

elasticsearch - 升级到 Elastic Search NEST 7.0.1 破坏了检查索引是否存在的代码

c# - 如何使用流畅的映射来映射Dictionary <string,MyDto>类型的属性

c# - 从Elasticsearch 5.5.0升级到7.5.1后的构建错误

elasticsearch - 安装Kopf-Elasticsearch

elasticsearch - 给定开放事件和关闭事件文档随时间绘制 "opened count"

c# - C#嵌套Elasticsearch地理点阵列索引未在Kibana中显示

c# - 使用NEST的Elasticsearch-无结果

elasticsearch - Elasticsearch DSL查询-获取所有匹配结果