zoukankan      html  css  js  c++  java
  • ElasticSearch-5.0.0安装中文分词插件IK

    Install IK

    源码地址:https://github.com/medcl/elasticsearch-analysis-ik,git clone下来。

    1.compile

    mvn package

    copy and unzip target/releases/elasticsearch-analysis-ik-{version}.zip to your-es-root/plugins/ik

    2.restart elasticsearch

    Tips:

    ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;

    ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。

    Changes

    5.0.0

    • 移除名为 ik 的analyzer和tokenizer,请分别使用 ik_smartik_max_word

    IK与Elasticsearch-5.0.0的集成步骤

    1.创建索引m8:

    PUT 'http://localhost:9200/m8'

    2.为索引(m8)及类型(logs)下的字段(message)设置分词器(分词器可选ik_smart或ik_max_word):

    PUT localhost:9200/m8 -d '
    {
        "settings" : {
            "analysis" : {
                "analyzer" : {
                    "ik" : {
                        "tokenizer" : "ik_smart"
                    }
                }
            }
        },
        "mappings" : {
            "logs" : {
                "dynamic" : true,
                "properties" : {
                    "message" : {
                        "type" : "string",
                        "analyzer" : "ik_smart"
                    }
                }
            }
        }
    }'

    关于两种不同分词的用处以及区别:
    2.1.使用方面的不同:

    其中我们在做索引的时候,希望能将所有的句子切分的更详细,以便更好的搜索,所以ik_max_word更多的用在做索引的时候,但是在搜索的时候,对于用户所输入的query(查询)词,我们可能更希望得比较准确的结果,例如,我们搜索“无花果”的时候,更希望是作为一个词进行查询,而不是切分为"无",“花”,“果”三个词进行结果的召回,因此ik_smart更加常用语对于输入词的分析。
    2.2.效率方面的不同:

    ik_max_word分词相对来说效率更加迅速,而ik_smart的效率比不上ik_max_word(个人做索引的时候将两种分词器进行尝试得出的结果,有误的话,望指正)

    3.用logstash-5.0.0上传数据:

    logstash -f ../config/input-file.conf

    4.测试分词效果:

    POST http://localhost:9200/m8/_analyze?analyzer=ik_smart&text=中文分词

    效果:

    5.查询测试:

    GET http://localhost:9200/m8/_search?q=中国

    效果:

  • 相关阅读:
    LeetCode 226. Invert Binary Tree
    LeetCode 221. Maximal Square
    LeetCode 217. Contains Duplicate
    LeetCode 206. Reverse Linked List
    LeetCode 213. House Robber II
    LeetCode 198. House Robber
    LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)
    LeetCode 171. Excel Sheet Column Number
    LeetCode 169. Majority Element
    运维工程师常见面试题
  • 原文地址:https://www.cnblogs.com/xuxy03/p/6050444.html
Copyright © 2011-2022 走看看