Elasticsearch2.3.4 配置同义词和中文分词
来源:互联网 发布:颜色矩阵 1.0f 编辑:程序博客网 时间:2024/06/06 02:22
1安装Elasticsearch2.3.4
elasticsearch安装的前提是jdk,elasticsearch5.x后需要jdk8来支持,本文安装的是es2.3.4版本故用jdk7。
下载es2.3.4
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz
解压es2.3.4
cd /usr/local/redis
tar -zxvf elasticsearch-2.3.4.tar.gz
配置elasticsearch
修改配置文件:vim $ES_HOME/config/elasticsearch.yml
cluster.name: zzht-es-clusternode.name: es-node-1network.host: xxx.xxx.xx.xxxhttp.port: 9200discovery.zen.ping.unicast.hosts: ["xxx.xxx.xx.xxx"]
同义词索引配置
index: analysis: analyzer: ik_syno: type: custom tokenizer: ik_max_word filter: [my_synonym_filter] ik_syno_smart: type: custom tokenizer: ik_smart filter: [my_synonym_filter] filter: my_synonym_filter: type: synonym synonyms_path: analysis/synonym.txt
配置elasticsearch集群
复制elasticsearch-node-1:
cp -rf /elasticsearch-cluster/elasticsearch-node-1 elasticsearch-node-2
修改配置(只需要修改节点名称和端口):
node.name: es-node-2http.port: 9201
修改完成后分别启动即可:
/elasticsearch-cluster/elasticsearch-node-1/bin/elasticsearch -d
/elasticsearch-cluster/elasticsearch-node-2/bin/elasticsearch -d
2.安装elasticsearch-analysis-ik
根据版本对应关系ik-1.9.4 和es2.3.4匹配(注意哦!)
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v1.9.4/elasticsearch-analysis-ik-1.9.4.zip
将elasticsearch-analysis-ik-1.9.4.zip解压到$ES_HOME/plugins/ik文件夹中。
修改配置 vim $ES_HOME/plugins/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">http://service.xxx.com/download/custom_main.dic</entry> <!--用户可以在这里配置远程扩展停止词字典--> <entry key="remote_ext_stopwords">http://service.xxx.com/download/ext_stopword.dic</entry></properties>
3.同义词注意事项
- 同义词字典或是IK用户自定义词典更新,必须每次重启elasticsearch才有效。
- 同义词词对是必须能被完成切分的词语。比如在synonyms.txt 文件中增加同义词对: ‘超级土豆’ – ‘土豆’ 。但在实际的搜索中用“超级土豆”是搜不到“土豆”的。因为“超级土豆”会被切分为多个词语。必须在http://service.xxx.com/download/custom_main.dic词典中新加“超级土豆”一词,才能用“超级土豆”一词搜出“土豆”。
4.创建索引和映射
curl -XPUT http://xxx:9200/goods
curl -XPOST http://xxx:9200/goods/goods_info/_mapping
{ "goods_info": { "_all": { "enabled": true, "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "properties": { "goodsId": { "type": "long" }, "createTime": { "type": "long" }, "price": { "type": "double" }, "refPrice": { "type": "double" }, "details": { "type": "string" }, "inventory": { "type": "long" }, "userId": { "type": "long" }, "name": { "type": "string", "store": "no", "term_vector": "with_positions_offsets", "analyzer": "ik_syno", "search_analyzer": "ik_syno", "include_in_all": "true", "boost": 8 }, "shelfTime": { "type": "long" }, "goodsImage": { "type": "string" }, "goodSizes": { "type": "string" } } }}
5.测试
在synonyms.txt 文件中增加
爱他美,爱她美,爱它美
并且需要将“爱她美“和”爱它美”放到custom_main.dic并发布大nginx,
请求:
http://xxx:9200/goods/_analyze?analyzer=ik_syno_smart&pretty=true&text=爱它美
查看同义词是否起作用。
- Elasticsearch2.3.4 配置同义词和中文分词
- 中文检索(分词、同义词、权重)
- Elasticsearch2.3.1中文分词ik插件安装
- elasticsearch2.3.1集成ansj中文分词
- solr6.6配置IK中文分词、IK扩展词、同义词、pinyin4j拼音分词
- paip.中文 分词 -- 同义词大全整理
- Lucene实现自定义中文同义词分词器
- Solr5.5 中文分词及同义词
- Elasticsearch2.1.0安装中文分词插件ik1.6
- Elasticsearch1.x 基于lc-pinyin和ik分词实现 中文、拼音、同义词搜索
- solr安装和配置中文分词器
- 配置solr4.10.0和中文分词IKAnalyzer
- IK 中文分词的配置和使用
- solr配置同义词,停止词,和扩展词库(IK分词器为例)
- ElasticSearch学习笔记(五)在logstash中配置分词器和同义词过滤器
- solr 6.2.0系列教程(二)IK中文分词器配置及添加扩展词、停止词、同义词
- elasticsearch ik分词实现 中文、拼音、同义词搜索
- 阿里云上给Elasticsearch2.3.4 安装ik分词插件
- 单例模式
- NPAPI插件开发详细记录:用VS2010开发NPAPI插件步骤
- Android各种获取代码调用栈的方法[补]
- Centos6.5安装mysql不能启动,应该安装mysql-server
- centos 安装theano
- Elasticsearch2.3.4 配置同义词和中文分词
- Eclipse导入idea 项目
- 【Ojdbc】使用Ojdbc 时需要注意的问题
- Intel DPDK包部署试验
- 单链表基本操作
- centos 提示下载空间不足解决办法
- win10, net framework 3.5 安装报错0x800F081F
- OSGI:Sring
- Html页面窗口框架与表单