【问题标题】:Logstash configuration: how to call the partial-update API from ElasticSearch output plugin?Logstash 配置:如何从 ElasticSearch 输出插件调用部分更新 API?
【发布时间】:2016-11-14 08:55:07
【问题描述】:

我正在尝试创建一个数据管道,其中 Logstash jdbc 插件每 5 分钟通过 SQL 查询获取一些数据,而 ElasticSearch 输出插件将来自输入插件的数据放入 ElasticSearch 服务器。我希望这个输出插件部分更新 ElasticSearch 服务器中的现有文档。我的 Logstash 配置文件如下所示:

input {
    jdbc {
        jdbc_driver_library => "/Users/hello/logstash-2.3.2/lib/mysql-connector-java-5.1.34.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_connection_string => "jdbc:mysql://localhost:13306/mysqlDB”
        jdbc_user => “root”
        jdbc_password => “1234”
        last_run_metadata_path => "/Users/hello/.logstash_last_run_display"
        statement => "SELECT * FROM checkout WHERE checkout_no between :sql_last_value + 1 and :sql_last_value + 5 ORDER BY checkout_no ASC"
        schedule => “*/5 * * * *"
        use_column_value => true
        tracking_column => “checkout_no”
    }
}

output {
    stdout { codec => json_lines }

    elasticsearch {
        action => "update"
        index => "ecs"
        document_type => “checkout”
        document_id => “%{checkout_no}"
        hosts => ["localhost:9200"]
    }
}

问题在于 ElasticSearch 输出插件似乎没有调用部分更新 API,例如 /{index}/{type}/{id}/_update。手册只列出了indexdeletecreateupdate等动作,但没有提到每个动作调用哪个REST API URL,即)update动作是否调用/{index}/ {type}/{id}/_update 或 /{index}/{type}/{id} api (upsert)。我想从弹性搜索输出插件中调用部分更新 api?有可能吗?

【问题讨论】:

    标签: elasticsearch logstash


    【解决方案1】:

    设置 doc_as_upsert => trueaction => "update" 在我的生产脚本中有效。

    output {
    
      elasticsearch {
        hosts => ["es_host"]
        document_id => "%{id}" # !!! the id here MUST be the same
        index => "logstash-my-index"
        timeout => 30
        workers => 1
        doc_as_upsert => true
        action => "update"
      }
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 这本手册仍然让我感到困惑。我想通过文档 ID 向 ElasticSearch 服务器中的现有文档添加一些 json 键。在这种情况下,我应该使用哪个选项?
      • 我觉得加doc_as_upsert => true应该够了。
      猜你喜欢
      • 2016-11-09
      • 2016-02-15
      • 1970-01-01
      • 2016-08-19
      • 2019-10-27
      • 2015-10-29
      • 2018-06-02
      • 2017-03-20
      • 1970-01-01
      相关资源
      最近更新 更多