先来一个标准分词(standard),配置如下:

curl -XPUT localhost:/local -d '{

    "settings" : {

        "analysis" : {

            "analyzer" : {

                "stem" : {

                    "tokenizer" : "standard",

                    "filter" : ["standard", "lowercase", "stop", "porter_stem"]

                }

            }

        }

    },

    "mappings" : {

        "article" : {

            "dynamic" : true,

            "properties" : {

                "title" : {

                    "type" : "string",

                    "analyzer" : "stem"

                }

            }

        }

    }

}'

index:local

type:article

default analyzer:stem (filter:小写、停用词等)

field:title  

测试:

# Index Data

curl -XPUT localhost:/local/article/ -d'{"title": "Fight for your life"}'

curl -XPUT localhost:/local/article/ -d'{"title": "Fighting for your life"}'

curl -XPUT localhost:/local/article/ -d'{"title": "My dad fought a dog"}'

curl -XPUT localhost:/local/article/ -d'{"title": "Bruno fights Tyson tomorrow"}'

# search on the title field, which is stemmed on index and search

curl -XGET localhost:/local/_search?q=title:fight

# searching on _all will not do anystemming, unless also configured on the mapping to be stemmed...

curl -XGET localhost:/local/_search?q=fight

例如:

Fight for your life

分词如下:

{"tokens":[

{"token":"fight","start_offset":,"end_offset":,"type":"<ALPHANUM>","position":},<br>{"token":"your","start_offset":,"end_offset":,"type":"<ALPHANUM>","position":},<br>{"token":"life","start_offset":,"end_offset":,"type":"<ALPHANUM>","position":}

]}

部署ik分词器

在elasticsearch.yml中配置  index.analysis.analyzer.ik.type : "ik"

delete之前创建的index,重新配置如下:

curl -XPUT localhost:/local -d '{

    "settings" : {

        "analysis" : {

            "analyzer" : {

                "ik" : {

                    "tokenizer" : "ik"

                }

            }

        }

    },

    "mappings" : {

        "article" : {

            "dynamic" : true,

            "properties" : {

                "title" : {

                    "type" : "string",

                    "analyzer" : "ik"

                }

            }

        }

    }

}'

测试:

curl 'http://localhost:9200/local/_analyze?analyzer=ik&pretty=true' -d'  

{  

    "text":"中华人民共和国国歌" 

}  

'  

{

  "tokens" : [ {

    "token" : "text",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "ENGLISH",

    "position" : 

  }, {

    "token" : "中华人民共和国",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "国歌",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  } ]

}

如果我们想返回最细粒度的分词结果,需要在elasticsearch.yml中配置如下:

index:

  analysis:

    analyzer:

      ik:

          alias: [ik_analyzer]

          type: org.elasticsearch.index.analysis.IkAnalyzerProvider

      ik_smart:

          type: ik

          use_smart: true

      ik_max_word:

          type: ik

          use_smart: false

测试:

curl 'http://localhost:9200/index/_analyze?analyzer=ik_max_word&pretty=true' -d'  

{  

    "text":"中华人民共和国国歌" 

}  

'  

{

  "tokens" : [ {

    "token" : "text",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "ENGLISH",

    "position" : 

  }, {

    "token" : "中华人民共和国",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "中华人民",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "中华",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "华人",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "人民共和国",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "人民",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "共和国",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "共和",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  }, {

    "token" : "国",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_CHAR",

    "position" : 

  }, {

    "token" : "国歌",

    "start_offset" : ,

    "end_offset" : ,

    "type" : "CN_WORD",

    "position" : 

  } ]

}

elasticsearch2.x ik插件的更多相关文章

  1. ElasticSearch搜索引擎安装配置中文分词器IK插件

    近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...

  2. elasticsearch 口水篇(8)分词 中文分词 ik插件

    先来一个标准分词(standard),配置如下: curl -XPUT localhost:9200/local -d '{ "settings" : { "analys ...

  3. Elastic ik插件配置热更新功能

    ik github地址:https://github.com/medcl/elasticsearch-analysis-ik 官网说明: 热更新 IK 分词使用方法 目前该插件支持热更新 IK 分词, ...

  4. 【自定义IK词典】Elasticsearch之中文分词器插件es-ik的自定义词库

    Elasticsearch之中文分词器插件es-ik 针对一些特殊的词语在分词的时候也需要能够识别 有人会问,那么,例如: 如果我想根据自己的本家姓氏来查询,如zhouls,姓氏“周”.      如 ...

  5. Elasticsearch安装ik中文分词插件(四)

    一.IK简介 IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包.从2006年12月推出1.0版开始, IKAnalyzer已经推出了4个大版本.最初,它是以开源项目Lu ...

  6. 在ElasticSearch中使用 IK 中文分词插件

    我这里集成好了一个自带IK的版本,下载即用, https://github.com/xlb378917466/elasticsearch5.2.include_IK 添加了IK插件意味着你可以使用ik ...

  7. ElasticSearch(三) ElasticSearch中文分词插件IK的安装

    正因为Elasticsearch 内置的分词器对中文不友好,会把中文分成单个字来进行全文检索,所以我们需要借助中文分词插件来解决这个问题. 一.安装maven管理工具 Elasticsearch 要使 ...

  8. ES之一:Elasticsearch6.4 windows安装 head插件ik分词插件安装

    准备安装目标:1.Elasticsearch6.42.head插件3.ik分词插件 第一步:安装Elasticsearch6.4 下载方式:1.官网下载 https://www.elastic.co/ ...

  9. Elastic Stack 笔记(二)Elasticsearch5.6 安装 IK 分词器和 Head 插件

    博客地址:http://www.moonxy.com 一.前言 Elasticsearch 作为开源搜索引擎服务器,其核心功能在于索引和搜索数据.索引是把文档写入 Elasticsearch 的过程, ...

随机推荐

  1. css3——transition属性和opacity属性

    [transition-duration] 是一个css3属性,规定完成过度效果需要花费的时间(一秒或毫秒计).语法:transition-duration: time;time :    规定完成过 ...

  2. 解决:cmd中运行monkeyrunner monkey_recorder.py报错: Can't open specified script file

    看lynnLi的博客monkeyrunner之录制与回放(七),遇到了一个问题,我在cmd中输入monkeyrunner monkey_recorder.py,却报错了: 当时第一个感觉时,先到\sd ...

  3. hdu5692 dfs序线段树

    这是补的知识点,按先序遍历的顺序建立dfs序,用左右两个值代表整个区间,因为dfs序最重要的特点就是子树的区间是连续的 建立线段树时,需要用重新标过的 下标来建立 #pragma comment(li ...

  4. tar 或 7z 备份项目

    mac, tar #!/bin/sh projPath=~/Developer projName=youku now=`date +%Y-%m-%d-%H-%M-%S` output=$projNam ...

  5. reloc: Permission denied

    群中一个朋友安装EBS是在db 2/5 步骤中遇到如下错误:  Checking for errors ... .end std out.sqlplus: error while loading sh ...

  6. Python学习之路day4-函数高级特性、装饰器

    一.预备知识 学习装饰器需理解以下预备知识: 函数即变量 函数本质上也是一种变量,函数名即变量名,函数体就变量对应的值:函数体可以作为值赋给其他变量(函数),也可以通过函数名来直接调用函数.调用符号即 ...

  7. 2018.7.28 A murder that scandalised Harvard and the world

    A murder that scandalised Harvard and the worldVisiting Boston in 1868, Charles Dickens was asked wh ...

  8. 2018.7.7 MBA -从专业到管理(1)—— 技术人才与的管理人才比较

    目录 1从基层员工到基层管理 专业,专长,专能,受赏识,团结同事 2从 基层管理到中层管理 重点:一专多能, 打造团队, 获取资源,对外沟通 3从中层到高层 重点:战略规划, 选拔人才 , 市场扩展

  9. mysql-jdbc创建connection理解

    jdbc源码分析(http://blog.csdn.net/brilliancezhou/article/details/5499738) 创建JDBC连接代码 Class.forName(" ...

  10. poj1325

    给出一系列任务,每个任务可以在机器A的某个模式,或者在机器B的某个模式下完成.机器A和B每切换一次模式需要重启一次.问完成这些任务,最少需要重启机器多少次? 把任务看作边 “重启”操作看作点 这道题就 ...