zoukankan      html  css  js  c++  java
  • es-07-head插件-ik分词器插件

    5.x以后, es对head插件的支持并不是特别好

    而且kibana的功能越来越强大, 建议使用kibana

    1, head插件安装

    在一台机器上安装head插件就可以了

    1), 更新,安装依赖

    sudo yum update -y

    2), 安装npm

    sudo yum install npm
    yum -y install git
    yum -y install bz2

    3), github 地址

    https://github.com/mobz/elasticsearch-head

    4), 安装

    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    #编译安装
    npm install
    # npm run start

    5) docker的安装方式: 

    目前只支持到5.x

    docker run -p 9100:9100 mobz/elasticsearch-head:5

    6), 在es的配置文件中

    http.cors.enabled: true
    http.cors.allow-orgin: "*"

    7) 之后重启 es 和 head插件

    npm run start

    8), 之后可以通过

    node1:9100 进行访问

    2, ik分词器插件

    需要在所有机器都可以进行安装

    5.x版本之后的ik分词器, 可以直接在mapping中定义了, 但也可以通过安装插件的方式实现

    githuib: https://github.com/medcl/elasticsearch-analysis-ik.git

    1), 几种不同的分词模式: 

    ik_smart :     智能分词, 粗力度

    ik_max_word :  最大词语, 细力度, 占用空间

    2) 安装

    有2种安装方式: 

      a), 直接使用es的插件下载安装

    ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip

      b) 手工安装

    下载并解压到目录即可

    plugins 目录下必须包含一层目录才可以

    create plugin folder cd your-es-root/plugins/ && mkdir ik
    
    unzip plugin to folder your-es-root/plugins/ik

    3), 之后创建使用ik

    create index

    put index_name

    create mapping 

    POST index_name
    {
        "mappings": {
            {
                "properties": {
                    "content": {
                        "type": "text",
                        "analyzer": "ik_max_word",
                        "search_analyzer": "ik_max_word"
                    }
                }
    
        }
    }

    4) 插入数据进行查询

    curl -XPOST http://localhost:9200/index/fulltext/1 -H 'Content-Type:application/json' -d'
    {"content":"美国留给伊拉克的是个烂摊子吗"}
    '
    curl -XPOST http://localhost:9200/index/fulltext/2 -H 'Content-Type:application/json' -d'
    {"content":"公安部:各地校车将享最高路权"}
    '
    curl -XPOST http://localhost:9200/index/fulltext/3 -H 'Content-Type:application/json' -d'
    {"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
    '
    curl -XPOST http://localhost:9200/index/fulltext/4 -H 'Content-Type:application/json' -d'
    {"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
    '

    查询

    curl -XPOST http://localhost:9200/index/fulltext/_search  -H 'Content-Type:application/json' -d'
    {
        "query" : { "match" : { "content" : "中国" }},
        "highlight" : {
            "pre_tags" : ["<tag1>", "<tag2>"],
            "post_tags" : ["</tag1>", "</tag2>"],
            "fields" : {
                "content" : {}
            }
        }
    }
    '

    5), 配置自己的字典等

    {plugins}/elasticsearch-analysis-ik-*/config/IKAnalyzer.cfg.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    <properties>
        <comment>IK Analyzer 扩展配置</comment>
        <!--用户可以在这里配置自己的扩展字典 -->
        <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
         <!--用户可以在这里配置自己的扩展停止词字典-->
        <entry key="ext_stopwords">custom/ext_stopword.dic</entry>
         <!--用户可以在这里配置远程扩展字典 -->
        <entry key="remote_ext_dict">location</entry>
         <!--用户可以在这里配置远程扩展停止词字典-->
        <entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry>
    </properties>

    6), 配置热更新词典

    <!--用户可以在这里配置远程扩展字典 -->
        <entry key="remote_ext_dict">location</entry>
         <!--用户可以在这里配置远程扩展停止词字典-->
        <entry key="remote_ext_stopwords">location</entry>

    7), 如果分词测试失败了, 使用

    curl -XGET "http://localhost:9200/_analyze?pretty&analyzer=ik_smart' -d '中华人民共和国M'

     8), 不建立索引的测试ik分词器

    GET _analyze?pretty
    {
      "analyzer": "ik_smart",
      "text":"安徽省长江流域"
    }

    最后贴一个别人家的mapping

    dynamic: true。  可以存储更多的属性, 但使用默认规则

  • 相关阅读:
    笔记本
    物料主档建立(PP模组)
    烦!烦!烦!
    Windows Live Writer试用
    SAP系统中发送公告的几种办法
    [CSS样式表之] 渐变色的实现
    今天终于开通了这个博客了
    MFC消息映射机制过程
    绘图
    C++ 内存分配和指针
  • 原文地址:https://www.cnblogs.com/wenbronk/p/9404686.html
Copyright © 2011-2022 走看看