使用 elasticsearch 作为输入和输出测试 logstash

Test logstash with elasticsearch as input and output

我已经使用 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"
               }
       }
      }

它returns

         {
   "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"}。

由于您的 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" } }}'    
   }
}