美文网首页
es6.2.4安装ik分词器

es6.2.4安装ik分词器

作者: 轻易流逝 | 来源:发表于2018-06-01 10:36 被阅读0次

    安装es

    1、安装 Elasticsearch 之前,你需要先安装一个较新版本的 JDK;
    2、从 elastic 的官网 <u>elastic.co/downloads/elasticsearch</u> 获取最新版本的 Elasticsearch,下载并解压适合你操作系统的 Elasticsearch 版本;
    3、编辑配置文件

    
    # 集群名称
    cluster.name: dev-es
    # 结点名称
    node.name: node-dev1
    
    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: ./path/to/data
    #
    # Path to log files:
    #
    path.logs: ./path/to/logs
    #
    # ----------------------------------- Memory -----------------------------------
    #
    # Lock the memory on startup:
    #
    bootstrap.memory_lock: false
    bootstrap.system_call_filter: false
    #
    #
    # Make sure that the heap size is set to about half the memory available
    # on the system and that the owner of the process is allowed to use this
    # limit.
    #
    # Elasticsearch performs poorly when the system is swapping the memory.
    #
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 192.168.16.21
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    #
    #以下参数是关于ip的访问策略,如果你发现其他ip地址访问不了就有可能是这两个参数没有配置
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #
    # --------------------------------- Discovery ----------------------------------
    #
    # Pass an initial list of hosts to perform discovery when new node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    #
    discovery.zen.ping.unicast.hosts: ["192.168.16.21", "192.168.16.22" ,"192.168.16.23"]
    #
    # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
    #
    discovery.zen.minimum_master_nodes: 2
    #
    # Block initial recovery after a full cluster restart until N nodes are started:
    #
    gateway.recover_after_nodes: 3
    #
    

    3、进入bin目录,执行elasticsearch脚本启动,这样启动的所有配置为默认配置。

    安装IK插件

    1、下载es的IK插件:https://github.com/medcl/elasticsearch-analysis-ik/tree/v5.6.3
    2、使用maven对下载的es-ik源码进行编译(mvn clean package -DskipTests)
    3、把编译后的target/releases下的elasticsearch-analysis-ik.zip文件拷贝到ES_HOME/plugins/ik目录下面,然后使用unzip命令解压
    4、重启es

    验证安装结果
    v5.6.3

    curl -XGET 'http://192.168.16.21:9200/_analyze?pretty&analyzer=standard' -d'认真学习,天天向上'
    
    {
      "tokens" : [
        {
          "token" : "认",
          "start_offset" : 0,
          "end_offset" : 1,
          "type" : "<IDEOGRAPHIC>",
          "position" : 0
        },
        {
          "token" : "真",
          "start_offset" : 1,
          "end_offset" : 2,
          "type" : "<IDEOGRAPHIC>",
          "position" : 1
        },
        {
          "token" : "学",
          "start_offset" : 2,
          "end_offset" : 3,
          "type" : "<IDEOGRAPHIC>",
          "position" : 2
        },
        {
          "token" : "习",
          "start_offset" : 3,
          "end_offset" : 4,
          "type" : "<IDEOGRAPHIC>",
          "position" : 3
        },
        {
          "token" : "天",
          "start_offset" : 5,
          "end_offset" : 6,
          "type" : "<IDEOGRAPHIC>",
          "position" : 4
        },
        {
          "token" : "天",
          "start_offset" : 6,
          "end_offset" : 7,
          "type" : "<IDEOGRAPHIC>",
          "position" : 5
        },
        {
          "token" : "向",
          "start_offset" : 7,
          "end_offset" : 8,
          "type" : "<IDEOGRAPHIC>",
          "position" : 6
        },
        {
          "token" : "上",
          "start_offset" : 8,
          "end_offset" : 9,
          "type" : "<IDEOGRAPHIC>",
          "position" : 7
        }
      ]
    }
    
    curl -XGET 'http://192.168.16.22:9200/_analyze?pretty&analyzer=ik_max_word' -d'认真学习,天天向上'
    
    {
      "tokens" : [
        {
          "token" : "认真学习",
          "start_offset" : 0,
          "end_offset" : 4,
          "type" : "CN_WORD",
          "position" : 0
        },
        {
          "token" : "认真",
          "start_offset" : 0,
          "end_offset" : 2,
          "type" : "CN_WORD",
          "position" : 1
        },
        {
          "token" : "学习",
          "start_offset" : 2,
          "end_offset" : 4,
          "type" : "CN_WORD",
          "position" : 2
        },
        {
          "token" : "天天向上",
          "start_offset" : 5,
          "end_offset" : 9,
          "type" : "CN_WORD",
          "position" : 3
        },
        {
          "token" : "天天",
          "start_offset" : 5,
          "end_offset" : 7,
          "type" : "CN_WORD",
          "position" : 4
        },
        {
          "token" : "向上",
          "start_offset" : 7,
          "end_offset" : 9,
          "type" : "CN_WORD",
          "position" : 5
        }
      ]
    }
    
    curl -XGET 'http://192.168.16.22:9200/_analyze?pretty&analyzer=ik_smart' -d'认真学习,天天向上'
    
    {
      "tokens" : [
        {
          "token" : "认真学习",
          "start_offset" : 0,
          "end_offset" : 4,
          "type" : "CN_WORD",
          "position" : 0
        },
        {
          "token" : "天天向上",
          "start_offset" : 5,
          "end_offset" : 9,
          "type" : "CN_WORD",
          "position" : 1
        }
      ]
    }
    

    v6.2.4
    在kibana上执行

    GET _analyze?pretty
    {
      "analyzer": "ik_smart",
      "text":"好好学习,天天向上"
    }
    
    image.png

    相关文章

      网友评论

          本文标题:es6.2.4安装ik分词器

          本文链接:https://www.haomeiwen.com/subject/efxxsftx.html