logstash同步mysql数据到es(一、es模板问题,请求返回400)

elasticsearch - Failed to install template {:message=>"Got response code '400' contacting Elasticsearch at URL 'http://localhost:9200/_template/ecs-logstash'", :exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError,

配置文件:

复制代码
input {
  jdbc {
    jdbc_driver_library => "/home/test/logstash/mysql-connector-j-8.0.32.jar"
    jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://localhost:3306/_test"
    jdbc_user => "root"
    jdbc_password => "root"
    #启用分页,默认false
    jdbc_paging_enabled => "true"
    #页面大小
    jdbc_page_size => "500"
    #是否记录上次运行的结果
    record_last_run => true
    #记录上次运行结果的文件位置
    last_run_metadata_path => "/usr/share/logstash/pipeline/lastvalue.txt"
    #是否使用数据库某一列的值,
    use_column_value => true
    tracking_column => "id"
    #numeric或者timestamp
    #tracking_column_type => "numeric"
    #如果为true则会清除last_run_metadata_path记录,即重新开始同步数据
    clean_run => false
    # sql语句文件,对于复杂的查询,可以放在文件中,如:
    # statement_filepath => "jdbc.sql"这个文件路径要跟jdbc.sql对应上
    #设置监听间隔。可以设置每隔多久监听一次什么的。
    #官方举例:
    #* 5 * 1-3 * 一月到三月的每天凌晨5点每分钟执行一次。
    #0 * * * *   将在每天每小时的第0分钟执行。
    #0 6 * * *   America/Chicago每天早上6:00(UTC / GMT -5)执行。
    #* * * * *   分、时、天、月、年,全部为*默认含义为每分钟查询一次
    schedule => "* * * * *"
    #索引类型
    #type => "jdbc"
    statement => "SELECT * FROM testORDER BY id ASC"
  }
}

output {
   elasticsearch {
                 hosts => "localhost:9200"
                 index => "test"
                 user => "elastic"
                 password => "elastic"
                 timeout => 3000
                 document_id => "%{id}"
                 #template => "/home/test/logstash/config/test.json"
                 }
}

这里由于我的es模板一直创建不上,所以就选择了注释掉,手动创建:

复制代码
curl -X PUT -u elastic:elastic http://localhost:9200/_template/test-H 'Content-Type: application/json' -d'
{
  "index_patterns": ["test*"],
  "mappings": {
    "properties": {
      "id": { "type": "integer" },
      "accession": { "type": "keyword" },
      "name": { "type": "keyword" },
      "comment_text": { "type": "text" },
      "sequence": { "type": "text" },
      "keyword": { "type": "keyword" }
    }
  }
}
'

看到报错信息请求的模板是:'http://localhost:9200/_template/ecs-logstash', ecs-logstash不是我的模板名字。

在conf文件中增加配置 template_name => "test"

重新运行logstash,发现请求正确了

后续还有一堆logstash问题总结一一奉上(头破血流不夸张~)

相关推荐
pride.li1 小时前
Git 笔记:将一段旧历史压缩成一个提交
大数据·elasticsearch·搜索引擎
逻极2 小时前
MySQL 从入门到精通:一个老 DBA 的实战心法
运维·数据库·mysql·从入门到精通·mysql从入门到精通
xuhaoyu_cpp_java2 小时前
事务学习(一)
数据库·经验分享·笔记·学习·mysql
最好的期待,未来可期3 小时前
MySQL语法的高级用法CASE WHEN
数据库·mysql
萌>__<新3 小时前
Git常见使用命令及易踩坑点
大数据·elasticsearch·搜索引擎
小陈工4 小时前
python Web开发从入门到精通(二十七)微服务架构设计原则深度解析:告别拆分烦恼,掌握治理精髓(下)
后端·python·mysql
1368木林森5 小时前
聊聊Mysql主从延迟的幽灵陷阱与解决方案
数据库·mysql
雪碧聊技术6 小时前
mysql表级锁的介绍
数据库·mysql
海棠蚀omo6 小时前
从概念到实战:手把手带你吃透 MySQL 事务核心原理
数据库·mysql
panzer_maus15 小时前
MySQL 索引介绍与索引优化的简单介绍
数据库·mysql