2016-08-12 34 views
0

我想使用NEST从elasticsearch检索更新的X行,但是当我使用.Sort()时,它将返回0个文档。如果我删除Sort(),它将返回文档,但不是最新的文档。ElasticSearch使用NEST检索更新的X行

任何想法如何从弹性检索最近的日志行或我做错了什么?

var result = elk.Search<FileBeatDto>(x => x 
     .From(0) 
     .Index("filebeat-*")     
     .Type(type)        
     .Query(q => 
      q.Match(qs => qs.Field("fields.asset_tag").Query(asset_tag)) && 
      q.Match(qs => qs.Field("message").Query(filter)) 
      ) 
     .Take(lines) 
     .Sort(ss => ss.Descending(p => p.timestamp)) 
     ); 
+0

什么'FileBeatDto'看起来像什么?和'type'类型的映射是什么样的? –

回答

0

时间戳和版本被检索为空。不确定是因为弹性他们是@timestamp和@version。

public class FileBeatDto 
{ 
    public DateTime timestamp { get; set; } 
    public string datetime { get; set; } 
    public DateTime received_at { get; set; } 
    public int offset { get; set; } 
    public string version { get; set; } 
    public string input_type { get; set; } 
    public int count { get; set; } 
    public Beat beat { get; set; } 
    public string host { get; set; } 
    public string source { get; set; } 
    public string message { get; set; } 
    public string type { get; set; } 
    public object fields { get; set; } 
    public List<string> tags { get; set; } 
} 

类型定义良好的文件类型是不是问题,如果我删除排序它返回文件罚款。

我得到这个错误:找不到[[timestamp]的映射为了排序