logstash把mysql數據導入es所需配置

logstash conf的output內容

output {
   if [type]=="bbs" {
           elasticsearch {
               hosts => ["http://es.service:9200"]
                   user => ""
                   password => ""
                   document_id => "%{tid}"
                   index => "bbs-v1"
                   template => "/data/tasks/logstash/template/bbs_template.json"
                   template_name => "bbs"
                   template_overwrite => true
           }
   }
#stdout { codec => rubydebug }
}

bbs_template.json

/***
官方文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html
https://blog.csdn.net/napoay/article/details/73100110?locationNum=9&fps=1#310-format
****/

{
    "template":"bbs*",
        "order":10,
        "settings":{
            "index.number_of_shards":5,
            "number_of_replicas": 0,
            "index.refresh_interval": "5s",
            "index.max_result_window":10000000
        },
        "mappings": {
            "_default_": {
                "_all": {
                    "enabled": true,
                    "norms": false
                },
                "dynamic_templates": [
                    {
                        "analyzer_fileds"/*可以自己隨便寫*/: {
                            //"path_match": "subject", 
                            "match": "subject", /*subject數據庫表字段*/
                            /*path_match|match  對於mysql來說,查出來就一個主json對象,沒有mongdb裏的子節點,
                            如:article.title 可以用  path_match(按路徑匹配)來匹配
                            title 直接用 match 匹配就行
                            */
                            "match_mapping_type": "string",/*配置數據類型*/
                            "mapping": {
                                "type": "text",/*text才能做es(5.多版本)的索引與拆詞,string不行*/
                                "norms": false,/*是否啓用搜索匹配評分排序,關閉節省空間*/
                                "analyzer": "ik_max_word",
                                "search_analyzer":"ik_smart"
                            }
                        }
                    },
                    {
                        "string_fields": {
                            /*配置所有的string的字段*/
                            "match": "*",
                            "match_mapping_type": "string",
                            "mapping": {
                                "type": "string",
                                "index": "not_analyzed",
                                "doc_values": true
                            }
                        }
                    }
                ],  
                "properties": {
                    "displayorder": {
                        "type": "integer"
                    },
                    "@timestamp": {
                        "type": "date",
                        "include_in_all": false
                    },
                    "@version": {
                        "type": "keyword",
                        "include_in_all": false
                    }
                }
            }
        }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章