<div id="content_views" class="markdown_views"> <!-- flowchart 箭头图标 勿删 --> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path> </svg> <blockquote> <p>ElasticSearch5.3安装IK分词器</p> </blockquote>java
<p>以前使用Elasticsearch安装head插件成功了,可是安装IK分词器却失败了。貌似是ElasticSearch5.0之后就不支持直接在elasticsearch.yml中配置IK了。缘由下面会说明。 <br> 首先下载: <br> <a href="https://www.elastic.co/downloads/elasticsearch" rel="nofollow" data-token="9f4ffd2c9982ccb2d6353c5c2248a2e3">https://www.elastic.co/downloads/elasticsearch</a> <br> <a href="https://github.com/medcl/elasticsearch-analysis-ik" rel="nofollow" data-token="0e8290e98b1edb53e7e9c1ed894c102f">https://github.com/medcl/elasticsearch-analysis-ik</a> <br> ,最新版本貌似是5.3 了。</p>node
<p>第一步 预处理:</p>git
<ol> <li>解压elasticsearch-5.3.0.zip>D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0</li> <li>解压elasticsearch-analysis-ik-5.3.0>D:\programfiles\softtools\elasticsearch\plugins\elasticsearch-analysis-ik-5.3.0</li> <li>编译elasticsearch-analysis-ik插件 cmd>D:\programfiles\softtools\elasticsearch\plugins\elasticsearch-analysis-ik-5.3.0>mvn clean package</li> </ol>github
<p>第二步 配置:</p>web
<ol> <li><p>IK配置,以下图是IK分词器config目录下的配置D:\programfiles\softtools\elasticsearch\plugins\elasticsearch-analysis-ik-5.3.0\config <br> <img src="https://img-blog.csdn.net/20170417173007224?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p></li> <li><p>在D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\config目录中新建ik文件夹,把上图中的IK配置文件放入ElasticSearch目录中的D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\config\ik目录下</p></li> </ol>bootstrap
<p><img src="https://img-blog.csdn.net/20170417173203262?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""> <br> ik里面的内容就是 第二步:1.IK配置 里面的配置。 <br> 3. 配置IK分词器 <br> 下图是经过mvn命令编译后生成的zip包 <br> <img src="https://img-blog.csdn.net/20170417173407402?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>windows
<p>将上图中的zip包放入D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\plugins\ik (ps:ik目录没有的话本身新建一个就好),进行解压 <br> 结果以下图所示:</p>浏览器
<p><img src="https://img-blog.csdn.net/20170417172939801?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""> <br> 整个安装就完成了。</p>markdown
<p>第三步 测试: <br> 1. 修改elasticsearch.yml中的配置 <br> 设置cluster.name,node.name,同时解开这两个配置的注释 <br> 设置http.port:9200,其余不须要增长配置了 <br> 2. windows下双击D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\bin\elasticsearch.bat <br> 不报错说明安装成功。 <br> <img src="https://img-blog.csdn.net/20170417173532216?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""> <br> 3. 安装Http链接访问工具,好比火狐插件httpRequester,安装完成后会在火狐浏览器右上角出现插件的标示。 <br> 4. 建立索引 <br> <img src="https://img-blog.csdn.net/20170417173642202?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>app
<pre class="prettyprint" name="code"><code class="hljs livecodeserver has-numbering" onclick="mdcp.signin(event)" style="position: unset;">content <span class="hljs-built_in">to</span> <span class="hljs-built_in">send</span>: { <span class="hljs-string">"settings"</span> : { <span class="hljs-string">"analysis"</span> : { <span class="hljs-string">"analyzer"</span> : { <span class="hljs-string">"ik"</span> : { <span class="hljs-string">"tokenizer"</span> : <span class="hljs-string">"ik_smart"</span> } } } }, <span class="hljs-string">"mappings"</span> : { <span class="hljs-string">"logs"</span> : { <span class="hljs-string">"dynamic"</span> : <span class="hljs-constant">true</span>, <span class="hljs-string">"properties"</span> : { <span class="hljs-string">"message"</span> : { <span class="hljs-string">"type"</span> : <span class="hljs-string">"string"</span>, <span class="hljs-string">"analyzer"</span> : <span class="hljs-string">"ik_smart"</span> } } } } } <div class="hljs-button signin" data-title="登陆后复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li></ul></pre>
<p>点击Put按钮,出现图右边的返回值,说明建立索引成功。 <br> 5. 进行分词测试: <br> <img src="https://img-blog.csdn.net/20170417173755658?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>
<p><img src="https://img-blog.csdn.net/20170417173816031?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>
<blockquote> <p>安装过程遇到的坑: <br> 1.将网上对使用IK的配置放到elasticsearch.yml中就会报以下的错误: <br> org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: node settings must not contain any index level settings <br> 这个不管怎么想都不明白,并且网上尚未几我的遇到过这种状况。</p> </blockquote>
<p>2.Caused by: java.lang.IllegalStateException: jar hell! <br> 将IK编译出来的jar,和source.jar两个文件放入elasticsearch的lib里后就出现了,有人说是版本问题,可是我选择的二者都是最新版本,而且对应。这里是由于lib里面有IK了,而后elasticsearch去读取plugin文件夹下的插件的时候又装载了一次,因而就出现了这个问题。将lib里的IK jar包删除,改从plugins里加载就没有问题了。网上也有很多是这样作的,可是确实这么作不正确。 <br> 在D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\logs会看到相应的错误日志。 <br> 3. Exception in thread “main” java.lang.IllegalStateException: Could not load plugin descriptor for existing plugin [analysis-ik]. Was the plugin built before 2.0? <br> Likely root cause: java.nio.file.NoSuchFileException: /home/es/es2/plugins/analysis-ik/plugin-descriptor.properties <br> 出现上面的异常是我一开始把编译出来的jar包放入D:\programfiles\softtools\elasticsearch\elasticsearch-5.3.0\plugins\ik里面了,实际上是要把D:\programfiles\softtools\elasticsearch\plugins\elasticsearch-analysis-ik-5.3.0\target\releases\elasticsearch-analysis-ik-5.3.0.zip解压到那个ik目录下面。 <br> 4. 为何没有在elasticsearch.yml配置IK相关的分词属性呢 <br> 5. 在github上 <a href="https://github.com/medcl/elasticsearch-analysis-ik" rel="nofollow" data-token="0e8290e98b1edb53e7e9c1ed894c102f">https://github.com/medcl/elasticsearch-analysis-ik</a>的使用文档说了: <br> <img src="https://img-blog.csdn.net/20170417173901438?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwNDA2NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述" title=""></p>
<p>5.0.0及其之后就不会上面两个分词器了,而使用两个参数去替代,同时根据上面的使用文档来讲,做者也没有说明要针对IK配置elasticsearch.yml。 <br> 整体来讲仍是遇到必定坎坷的,网上不少ES的文章对于新版本都不适用了。我重新将5.0.0的安装环境所有删除而后引入最新版本,才搞定了IK分词器。最新版本的ES安装head插件应该没有什么问题了,毕竟head也没有要求要对5.0.0之后的版本进行安装配置的改动。</p> 原文地址:https://blog.csdn.net/u010504064/article/details/70214040 </div>