zoukankan      html  css  js  c++  java
  • Elasticsearch6.x和7.x版本常用插件汇总

    elasticsearch插件汇总

    基于es 7.3版本试用。

    一、安全插件

    1、x-pack

    a、介绍

    包括安全(x-pack-security),监视(x-pack-watcher),警报(x-pack-monitoring),报表(x-pack-graph),Elasticsearch SQL(x-pack-sql),跨集群复制(x-pack-ccr)、x-pack-upgrade、x-pack-rollup和机器学习(x-pack-ml)。7.x版本中,es的安全核心功能免费使用。

    b、安装

    es7.x版本以默认安装好x-pack。修改配置激活即可。

    #在elasticsearch.yml最后添加
    xpack.security.enabled: true
    xpack.security.audit.enabled: true
    #basic表示xpack使用基础版license,否则无法启动
    xpack.license.self_generated.type: basic
    xpack.security.transport.ssl.enabled: true
    

      

    重启es执行
    ./elasticsearch-setup-passwords interactive 
    会引导设置各种密码,包括elastic、kibana、apm_system、logstash_system、beats_system、remote_monitoring_user 
    c、使用

    默认用户名elastic,例如

    #curl请求
    curl -XGET -u "elastic:123456" http://192.0.0.1:9200/_cat/indices?v
    #http请求
    header添加
    key=Authorization  value = Basic ZWxhc3RpYzoxMjM0NTY=

    将username:secret进行base64加密得到 dXNlcm5hbWU6c2VjcmV0 然后前面加上一个Basic和空格, 构造一个字符串形如: Basic dXNlcm5hbWU6c2VjcmV0 然后添加到http的header中Authorization作为键,该字符串为值。
    若没添加Authorization,restful请求时报错,返回如security_exception、401

    d、结合kibana

    es启用x-pack后,kibana会新增用户和角色管理菜单。kibana登录需要输入密码

    e、es6.x版本使用x-pack

    在es6.x中使用安全功能,需要在kibana中升级license。购买一个icense或申请一个30天的试用。 在 Kibana 中访问 Management -> Elasticsearch -> License Management。选择试用 然后在elasticsearch.yml添加如下配置

    xpack.security.enabled: true
    xpack.ml.enabled: true
    xpack.license.self_generated.type: trial    

    重启es
    在es的bin下执行如下命令,设置密码

    elasticsearch-setup-passwords interactive

    在kibana.yml中配置

    elasticsearch.username: "elastic"
    elasticsearch.password: "123456"

    重启kibana,获得试用30天

    二、分词插件

    1、ik分词

    a、介绍

    最流行的分词插件

    b、安装
    cd /bin
    ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.0/elasticsearch-analysis-ik-7.3.0.zip 
    c.使用
    i.创建索引
    1.create a index
    curl -XPUT http://localhost:9200/index
    2.create a mapping
    curl -XPOST http://localhost:9200/index/_mapping -H 'Content-Type:application/json' -d'
    {
            "properties": {
                "content": {
                    "type": "text",
                    "analyzer": "ik_max_word",
                    "search_analyzer": "ik_smart"
                }
            }
    
    }'
    

      

    analyzer说明: ik_smart: 会做最粗粒度的拆分 ik_max_word: 会将文本做最细粒度的拆分。 
    ii.分词查询
    curl -XPOST http://localhost:9200/index/_search  -H 'Content-Type:application/json' -d'
    {
        "query" : { "match" : { "content" : "中国" }},
        "highlight" : {
            "pre_tags" : ["<tag1>", "<tag2>"],
            "post_tags" : ["</tag1>", "</tag2>"],
            "fields" : {
                "content" : {}
            }
        }
    }
    

      

    2、pinyin

    a、介绍

    pinyin插件能够将文档和查询条件在汉字和拼音间转换

    b、安装
    ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.3.0/elasticsearch-analysis-pinyin-7.3.0.zip
    

      

    c.使用
    i.创建索引
    PUT /medcl/ 
    {
        "settings" : {
            "analysis" : {
                "analyzer" : {
                    "pinyin_analyzer" : {
                        "tokenizer" : "my_pinyin"
                        }
                },
                "tokenizer" : {
                    "my_pinyin" : {
                        "type" : "pinyin",
                        "keep_separate_first_letter" : false,
                        "keep_full_pinyin" : true,
                        "keep_original" : true,
                        "limit_first_letter_length" : 16,
                        "lowercase" : true,
                        "remove_duplicated_term" : true
                    }
                }
            }
        }
    }
    

      

    ii.查询
    GET /medcl/_analyze
    {
      "text": ["刘德华"],
      "analyzer": "pinyin_analyzer"
    }
    

      

    3、smartcn

    a、介绍

    中科院分词器,和ik类似。不同点是smartcn无法自定义词库

    b、安装
    ./elasticsearch-plugin install https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-smartcn/analysis-smartcn-7.3.0.zip
    

      

    c.使用

    类似ik tokenizer为smartcn

    4、icu

    a、介绍

    Elasticsearch的 ICU 分析器插件 使用 国际化组件 Unicode (ICU) 函数库(详情查看 site.project.org)提供丰富的处理 Unicode 工具。 这些包含对处理亚洲语言特别有用的 icu_分词器 ,还有大量对除英语外其他语言进行正确匹配和排序所必须的分词过滤器。

    b、安装
    ./elasticsearch-plugin install analysis-icu
    

      

    5、ik或smart与pinyin组合使用

    es分析器实际上是三个功能的封装,字符过滤器->分词器->token过滤器,按顺序执行 创建自定义分析器,格式如下

    PUT localhost:9200/mytest
    {
        "setting": {
            "analysis": {
                "char_filter": { 自定义的字符过滤器 },
                "tokenizer": { 自定义的分词器 },
                "filter": { 自定义的token过滤器 },
                "analyzer": { 自定义的分析器,可以将上面的char_filter、tokenizer、filter用不同的组合拼起来,形成不同的分析器 }
            }
        }
    }
    

      

    例如ik和拼音组合

    http://localhost:9200/article_ik_pinyin
    {
    	"settings": {
    		"number_of_shards": "6",
    		"number_of_replicas": "1",
    		"index":{
    			"analysis": {
    				"analyzer": {
    					"ik_pinyin_analyzer": {
    						"type":"custom",
    						"tokenizer": "ik_max_word",
    	        			"filter": "pinyin_filter"
    					}
    				},
    				"filter":{
    		          "pinyin_filter":{
    		            "type": "pinyin",
    		            "keep_first_letter": false
    		          }
    		        }
    			}
    		}
    	},
    	"mappings": {
    		"article_ik_pinyin": {
    			"properties": {
    				"id": {
    					"type": "text"
    				},
    				"title": {
    					"analyzer": "ik_pinyin_analyzer",
    					"type": "text"
    				}
    			}
    		}
    
    	}
    }
    

      

    三、文本解析插件

    4、ingest attachment plugin

    a、介绍

    这个是基于Apache 文本扩展库Tika插件之上开发的一款适合elasticsearch文本解析插件。在ES5之前使用的是mapper-accachment。ElasticSearch只能处理文本,不能直接处理文档。
    Ingest-Attachment是一个开箱即用的插件,替代了较早版本的Mapper-Attachment插件,使用它可以实现对(PDF,DOC,EXCEL等)主流格式文件的文本抽取及自动导入。Elasticsearch5.x新增一个新的特性IngestNode,此功能支持定义命名处理器管道pipeline,pipeline中可以定义多个处理器,在数据插入ElasticSearch之前进行预处理。 而Ingest Attachment Processor Plugin提供了关键的预处理器attachment,支持自动对入库文档的指定字段作为文档文件进行文本抽取。
    由于ElasticSearch是基于JSON格式的文档数据库,所以附件文档在插入ElasticSearch之前必须进行Base64编码。

    b、安装
    ./elasticsearch-plugin install ingest-attachment
    

      

    四、SQL支持

    1、x-pack-sql

    es7.x版本的x-pack自带es sql

    a、使用例如
    http://localhost:9200/_sql
    {
        "query": "SELECT * FROM article_ik_pinyin"
    }
    

      

    详见

    2、elasticsearch-sql

    a、介绍

    支持到es6.8
    https://github.com/NLPchina/elasticsearch-sql/

    b、安装
    ./elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/6.5.4.0/elasticsearch-sql-6.5.4.0.zip
    

      

    c、使用
    curl -X GET "localhost:9200/_sql" -H 'Content-Type: application/json' -d'select * from article_smartcn_pinyin  limit 10'
    

      

    五、可视化

    1、kibana

    a、介绍

    es官方提供的可视化套件,集成了es开发工具、报表、仪表盘、数据挖掘等功能https://www.elastic.co/guide/en/kibana/current/targz.html
    kibana6.7+才支持汉化

    b、安装
    kibana安装版本要和es对应wget https://artifacts.elastic.co/downloads/kibana/kibana-7.3.0-linux-x86_64.tar.gztar -xzvf kibana-7.3.0-linux-x86_64.tar.gz
    
    修改config/kibana.yml
    i18n.locale: "zh-CN"
    server.port: 5601
    server.host: "内网ip"
    ibana.index: ".kibana"
    elasticsearch.hosts: ["http://192.168.0.1:9200"]
    es有配置x-pack的话修改 elasticsearch.username: "elastic" elasticsearch.password: "123456"

      

     启动 
    ./bin/kibana
    

      

     
  • 相关阅读:
    suse12安装详解
    Centos7上部署openstack mitaka配置详解(将疑难点都进行划分)
    菜鸟帮你跳过openstack配置过程中的坑[文末新添加福利]
    openstack中dashboard页面RuntimeError: Unable to create a new session key. It is likely that the cache is unavailable.
    Multiple network matches found for name 'selfservice', use an ID to be more specific.报错
    查看 SELinux状态及关闭SELinux
    SELinux深入理解
    IP地址、子网掩码、网络号、主机号、网络地址、主机地址
    Oracle job procedure 存储过程定时任务
    POI文件导出至EXCEL,并弹出下载框
  • 原文地址:https://www.cnblogs.com/yobit/p/11376453.html
Copyright © 2011-2022 走看看