【问题标题】:Test logstash with elasticsearch as input and output使用 elasticsearch 作为输入和输出测试 logstash
【发布时间】:2017-10-14 03:50:14
【问题描述】:

我已将带有 Elasticsearch 的 logstash 配置为输入和输出参数,如下所示:

输入

      {
         elasticsearch {
         hosts =>  ["hostname" ]
        index => 'indexname'        
        type => 'type'
        user => 'username'      
        password => 'password'
        docinfo => true
        query => '{ "query": { "match": { "first_name": "mary" } }}'    
       }
     }

输出

  {
   elasticsearch {
    hosts => ["hostname" ]
    index => 'indexname'                
    user => 'username'
    password => 'password'    
    }
   }

我的索引数据如下:

    PUT person/person/3 
    { 
     "first_name" : "mary" 
    }
    PUT person/person/4
    { 
    "first_name" : "mary.m" 
    }
     PUT person/person/5
    { 
    "first_name" : "mary.k" 
    }

当我在 ES 上运行以下查询时

   GET indexname/_search
   {
    "query": {
     "match": {
       "first_name": "mary"
               }
       }
      }

返回

         {
   "took": 1,
     "timed_out": false,
       "_shards": {
         "total": 5,
        "successful": 5,
         "failed": 0
            },
          "hits": {
             "total": 1,
            "max_score": 0.2876821,
             "hits": [
              {
               "_index": "person",
                 "_type": "person",
                   "_id": "3",
                "_score": 0.2876821,
             "_source": {
             "first_name": "mary"
                       }
                    }
                 ]
               }
             }

虽然 logstash 管道已成功启动,但它不会在 ES 中记录此查询,因为我在输入部分使用查询作为 "match": { "first_name": "mary"}。

【问题讨论】:

  • 看来您采购的索引与您将文档接收到的索引相同。你的用例到底是什么?如果查询没有产生任何文档,那么 Logstash 也将无法加载任何文档。
  • 我已经更新了我的问题
  • 你确定你是在indexname索引而不是person搜索???
  • 好的.. 人只是索引名。我更改了它的 indexname 以隐藏它的实际名称。在实际场景中,我只在任何地方使用人
  • 那么您确定您的用户名/密码凭据吗?

标签: elasticsearch logstash nest elasticsearch-plugin


【解决方案1】:

由于您的 ES 在 HTTPS 上运行,您需要将 ssl => true 添加到您的 elasticsearch 输入配置中

input {
   elasticsearch {
      hosts =>  ["hostname" ]
      index => 'indexname'        
      type => 'type'
      user => 'username'      
      password => 'password'
      docinfo => true
      ssl => true                                 <--- add this
      query => '{ "query": { "match": { "first_name": "mary" } }}'    
   }
}

【讨论】:

  • 它给出以下错误错误:初始化:名称或服务未知异常:Faraday::ConnectionFailed 堆栈:org/jruby/ext/socket/RubyTCPSocket.java:129:in initialize' org/jruby/RubyIO.java:1197:in open' D:/Sushil/logstash-5.4.0/vendor/jruby/lib/ruby/1.9/net/http.rb:763:in connect' org/jruby/ext/timeout/Timeout.java:98:in timeout' D:/Sushil/logstash-5.4.0/vendor/jruby/ lib/ruby/1.9/net/http.rb:763:in `connect'
  • ca_file 位于何处?如何获取路径
  • 确保删除 hosts 参数中的 https:// 方案。效果更好?
  • 它现在没有抛出任何错误,但在使用搜索查询后它也没有在 ES 中记录任何内容
  • 我现在可以在 ES 中登录,但它使用 _type 日志连续记录在我的人员索引中。所以假设如果将查询输入为 query => '{ "query": { "match ": { "first_name": "mary"}}}' 在输出中它连续记录在我的索引中以获取玛丽结果,尽管我没有查询它。我无法理解 logstash 的工作原理
猜你喜欢
  • 2015-05-09
  • 1970-01-01
  • 2017-02-18
  • 2015-10-29
  • 1970-01-01
  • 1970-01-01
  • 2019-10-27
  • 1970-01-01
  • 2016-02-15
相关资源
最近更新 更多