繁体   English   中英

什么是Elasticsearch中带有Logstash文档的POCO对象

[英]What is POCO Object with the Logstash document in Elasticsearch

我在从LogStash导入的ElasticSearch中有文档,例如:

{
  "_index": "logstash-2018.03.13",
  "_type": "logs",
  "_id": "AWIdXdfYQVCHQ1iyikAx",
  "_score": 1,
  "_source": {
    "Action": "view",
    "offset": 34497789,
    "Ip": "113.161.25.104",
    "Url": "http://vietnamnet.vn/",
    "tags": [
      "beats_input_codec_plain_applied"
    ],
    "CateAlias": "trang-chu",
    "ActionDate": "2018-03-13 10:18:31",
    "@timestamp": "2018-03-13T03:18:31.000Z",
    "WebsiteCode": "VietNamNet",
    "@version": "1",
    "beat": {
      "hostname": "Tracking59",
      "name": "Tracking59",
      "version": "5.4.3"
    },
    "host": "Tracking59",
    "ArticleId": 0,
    "Domain": "vietnamnet.vn"
  },
  "fields": {
    "@timestamp": [
      1520911111000
    ]
  }
}

我使用NEST lib连接并从Elasticsearch获取数据。 我阅读并遵循链接: https ://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html按照@ sramalingam24的答案,我创建了我的POCO类:

 public class Beat
{
    public string hostname { get; set; }
    public string name { get; set; }
    public string version { get; set; }
}

public class LogItem
{
    public string Action { get; set; }
    public int offset { get; set; }
    public string Ip { get; set; }
    public string Url { get; set; }
    public IList<string> tags { get; set; }
    public string CateAlias { get; set; }
    public string ActionDate { get; set; }
    public DateTime @timestamp { get; set; }
    public string WebsiteCode { get; set; }
    public string @version { get; set; }
    public Beat beat { get; set; }
    public string host { get; set; }
    public int ArticleId { get; set; }
    public string Domain { get; set; }
}

但是当我搜索时,找不到任何文档匹配此对象。 我的代码在这里搜索:

var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
            .DefaultIndex("logstash-2018.03.12");

            var client = new ElasticClient(settings);
            var result = client.Search<LogItem>(s => s.Index("logstash-2018.03.12").Type("logs")
                                                    .Query(
                                                        q => q.Match(m => m.Field(f => f.CateAlias).Query("trang-chu"))
                                                    )
                                                );
            Console.Write(result.Total);

            var total = client.Count<dynamic>().Count;
            Console.Write(total);
            Console.ReadLine();

他们两个都返回:0。当我使用Kibana进行查询时,我得到了很多物品。

有几种方法可以做到这一点

  1. 您可以使用上面文档的_source部分和jsonutils.com生成所需的poco规范

  2. 只需使用

var searchRes = client.Search <动态>(...)

而不是指定poco

  1. 使用Newtonsoft.Json nuget,然后您也可以

var searchRes = client.Search <Newtonsoft.Json.Linq.JObject>(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM