【问题标题】:Issue connecting to elastic search from logstash in input从输入中的logstash连接到弹性搜索的问题
【发布时间】:2016-09-07 08:22:49
【问题描述】:

我想从 oracle 导入数据,并想将导入数据的参数之一传递给弹性搜索以获取其他一些详细信息。

例如:- 如果我有一个从 oracle db 获得的员工 ID,比如 100 行,我想将所有这 100 个员工 ID 传递给弹性搜索并获取员工姓名和薪水。

我现在可以从 oracle 检索数据,但无法连接到弹性搜索。我也不确定什么是更好的方法来做到这一点。
我正在使用 log stash 2.3.3 和 elastic search log stash filter 插件。

 input {
       jdbc {
        jdbc_connection_string => "jdbc:oracle:thin:@<dbhost>:<port>:<sid>"
        # The user we wish to execute our statement as
        jdbc_user => “user"
        jdbc_password => “pass"
        # The path to our downloaded jdbc driver
        jdbc_driver_library => “<path>"
        # The name of the driver class for oracle
        jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
        # our query
        statement => "SELECT empId, desg from Employee"
    }
    elasticsearch {
      hosts => "https://xx.corp.com:9200"
        index => “empdetails”
    }
   }
   output {
    stdout { codec => json_lines }
   }

由于弹性搜索,我收到以下错误。

插件出现不可恢复的错误。将重新启动此插件。

插件:["https://xx.corp.com:9200"], index=>"empdetails", query=>”empId:'1001'", codec=>"UTF-8">, scan=>true, size=>1000 , scroll=>"1m", docinfo=>false, docinfo_target=>"@metadata", docinfo_fields=>["_index", "_type", "_id"], ssl=>false>

错误:[401] {:level=>:error}

【问题讨论】:

  • 我可以修复上述错误,现在我可以从弹性搜索中获取数据。但是任何人仍然可以给我任何关于如何从 jdbc 传递数据并从弹性搜索中获取相应数据的指针。我对记录 stash 非常陌生,因此非常感谢任何信息。
  • 更新代码如下 - elasticsearch { ssl => true hosts => "xx.corp.com:9200" index => "empdetails" query => '{ "query": { "match ": { "empId": "1001" } } }' 用户 => "admin" 密码 => "admin" }

标签: elasticsearch logstash


【解决方案1】:

您需要使用elasticsearch filter 而不是elasticsearch input

input {
   jdbc {
    jdbc_connection_string => "jdbc:oracle:thin:@<dbhost>:<port>:<sid>"
    # The user we wish to execute our statement as
    jdbc_user => “user"
    jdbc_password => “pass"
    # The path to our downloaded jdbc driver
    jdbc_driver_library => “<path>"
    # The name of the driver class for oracle
    jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
    # our query
    statement => "SELECT empId, desg from Employee"
   }
}
filter {
  elasticsearch {
    hosts => ["xx.corp.com:9200"]
    query => "empId:%{empId}"
    user => "admin"
    password => "admin"
    sort => "empName:desc"
    fields => {
      "empName" => "empName" 
      "salary" => "salary" 
    }
  }
}
output {
  stdout { codec => json_lines }
}

因此,通过 JDBC 获取的每条记录都将被 ES 中找到的相应数据丰富。

【讨论】:

  • 谢谢瓦尔。我已经想通了,并将其更改为弹性搜索过滤器,但我遇到了另一个问题,我得到 "No mapping found for [@empName] in order on" 。过滤器中更新的代码是 filter { elasticsearch { ssl => "true" hosts => .... user => "admin" password => "admin" index => .... query => "empId: R1001"字段 => ["@empName", "@salary"] 排序 => "@empName:desc" } }
  • 您要排序的字段的名称是什么?你确定是@empName 而不仅仅是empName
  • empName 字段存储在弹性搜索中。
  • 好的,然后简单地改变这个sort =&gt; "empName:desc"
  • 好的,是的,这是错误的。我尝试替换时间戳并错过了@。该错误不再出现。知道为什么我可能会得到 - 无法查询弹性搜索以前的事件.... @lut={}>>, :error=>#, :level=>:warn}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2022-12-04
  • 2019-10-13
  • 2022-10-23
  • 1970-01-01
相关资源
最近更新 更多