我正在尝试创建一个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/