Elasticsearch简单使用和环境搭建
Elasticsearch简单使用和环境搭建
1 Elasticsearch简介

Elasticsearch是一个可用于构建搜索应用的成品软件,它最早由Shay Bannon创建并于2010年2月发布。现在已经非常流行,成为商业解决方案之外一个开源的重要选择。
Elasticsearch是一个基于Lucene的搜索服务器,提供一个分布式多用户能力的全文搜索引擎,基于RESTful web借口,使用Java开发,在Apache许可条款下开发源代码发布。做到准实时搜索、稳定、可靠、安装使用方便。
Elasticsearch具有合理的默认配置,默认就是分布式工作模式,使用对等架构(P2P)避免单点故障(SPOF),易于横向扩展新的节点。此外由于没有对索引中的数据结构强行添加限制,从而允许用户调整现有数据模型。
2 Elasticsearch下载安装
官网下载页面中有ZIP、TAR、DEB、RPM几种格式的安装包提供下载。
step1 下载

下载并解压Elasticsearch的最新版本
step2 运行

在Uinx上运行命令: bin/elasticsearch,在Windows环境下运行命令:bin\elasticsearch.bat。
step3 访问

运行命令: curl -X GET http://localhost:9200/
结果:

3 插件的安装和使用
3.1 head插件
elasticsearch-head是elastic search集群的一个web前端。源代码托管在github.com,地址是:https://github.com/mobz/elasticsearch-head。这是一个学习elasticsearch的利器。
安装
有两种方式来使用head。一种方式是作为ealsticsearch的插件,另一种是将其作为一个独立的webapp来运行。这里将其作为elasticsearch插件来使用。
在线安装步骤:
- sudo elasticsearch/bin/plugin install mobz/elasticsearch-head
- 在浏览器中浏览,http://localhost:9200/_plugin/head/
离线安装步骤:
- wget https://github.com/mobz/elasticsearch-head/archive/master.zip
- elasticsearch/bin/plugin file:/path/elasticsearch-head-master.zip
- 在浏览器中浏览,http://localhost:9200/_plugin/head/

3.2 IK分词插件
这里使用的是elasticsearch-analysis-ik,这是一个将Lucence IK分词器集成到elasticsearch的ik分词器插件,并且支持自定义的词典。源代码托管在github.com上,地址是:https://github.com/medcl/elasticsearch-analysis-ik。
安装
- 1,在github上下载同elasticsearch匹配的版本
- 2,将下载zip包,在解压到elasticsearch/plugin/ik下
- 3,重启elasticsearch
3.2.1测试IK分词
IK分词安装后有三种分词策略:ik、ik_max_word和ik_smart。ik和ik_max_word分词效果相同,对输入文本根据词典穷尽各种分割方法是细力度分割策略。ik_smart会对输入文本根据词典以及歧义判断等方式进行一次最合理的粗粒度分割。可以在Terml中使用curl查看分词效果。
- 分词策略ik/ik_max_word
$ curl -G 'localhost:9200/_analyze?analyzer=ik&pretty=true' --data-urlencode "text=中华人民共和国国歌"
{
"tokens" : [ {
"token" : "中华人民共和国",
"start_offset" : 0,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 0
}, {
"token" : "中华人民",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 1
}, {
"token" : "中华",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 2
}, {
"token" : "华人",
"start_offset" : 1,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "人民共和国",
"start_offset" : 2,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 4
}, {
"token" : "人民",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 5
}, {
"token" : "共和国",
"start_offset" : 4,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 6
}, {
"token" : "共和",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 7
}, {
"token" : "国",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 8
}, {
"token" : "国歌",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 9
} ]
}
- 分词策略ik_smart
$ curl -G 'localhost:9200/_analyze?analyzer=ik_smart&pretty=true' --data-urlencode "text=中华人民共和国国歌"
{
"tokens" : [ {
"token" : "中华人民共和国",
"start_offset" : 0,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 0
}, {
"token" : "国歌",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 1
} ]
}
注
这里使用的版本分别是:
| soft | version |
|---|---|
| elasticsearch | 2.4.0 |
| elasticsearch-head | master分支的当前版本 |
| elasticsearch-analysis-ik | 1.10.0 |
Elasticsearch简单使用和环境搭建的更多相关文章
- 分布式搜索ElasticSearch单机与服务器环境搭建
从上方插件官网中下载适合的dist包,然后解压.进入bin目录,可以看到一堆sh脚本.在bin目录下创建一个test.sh: bin=/home/csonezp/Dev/elasticsearch-j ...
- 最简单的SVN环境搭建过程
本文简单描述最简单的SVN环境搭建过程 搭建环境:windows (个人验证了windows2003,windows xp) 使用软件:Setup-Subversion-1.6.17 //Serve ...
- Elasticsearch快速入门和环境搭建
内容概述 什么是Elasticsearch,为什么要使用它? 基础概念简介 节点(node) 索引(index) 类型映射(mapping) 文档(doc) 本地环境搭建,创建第一个index 常用R ...
- elasticsearch 源码本地环境搭建
elasticsearch6.0.0 源码本地环境搭建步骤如下: 1.资源准备 ElasicSearch版本:6.0.0: https://github.com/elastic/elasticsear ...
- 渣渣菜鸡的 ElasticSearch 源码解析 —— 环境搭建
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/08/25/es-code01/ 软件环境 1.Intellij Idea:2018.2版本 2. ...
- springMVC的简单了解和环境搭建
一,什么mvc 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计思想.它主要通过 分离模型.视图及控制器在应用程序中的角色 将业务逻辑从界面中解耦.通常, 模型负责封装应用程 ...
- spring boot-1.简单介绍及环境搭建
1.简介 spring boot 是在spring 基础上进行了全面整合的架构,个人认为优点在于以下几点: 1.简化配置,甚至零配置即可开发出一个web应用.spring boot 默认配置了大量的s ...
- Appium+python(1)简单的介绍环境搭建
环境搭建其实并不难,只不过安装的东西有点多,要加的环境变量有点多. 链接:https://pan.baidu.com/s/1nwLhNIT 密码:56wn 这个压缩包里要用的都有了,只需要下载,然后安 ...
- Ionic01 简单介绍、环境搭建、创建项目、项目结构、创建组件、创建页面、子页面跳转
1 Ionic 基本介绍 Ionic 是一款基于 Angular.Cordova 的强大的 HTML5 移动应用开发框架 , 可以快速创建一个跨平台的移动应用.可以快速开发移动 App.移动端 WEB ...
随机推荐
- Winform 常用的方法
一,Winform 如何内嵌窗体 1,判断窗体中是否以还有内嵌窗体 private void ClosePreForm() { foreach (Control item in this.spCont ...
- [android] 手机卫士接收打电话广播显示号码归属地
使用广播接收者接收打电话的意图,显示号码归属地 新建一个类OutCallReceiver继承系统的BroadcastReceiver 重写onReceive()方法 调用getResultData() ...
- .NET异常处理的动作策略(Action Policy)
SQL Server 2008基于策略的管理,基于策略的管理(Policy Based Management),使DBA们可以制定管理策略,并将这些策略应用到服务器.数据库以及数据环境中的其他对象上去 ...
- Xshell 6连接本机VirtualBox CentOS 6.5成功方案
网上的文章铺天盖地,适合自己的没有... 最后老办法:文章+经验+尝试 = 成功,哈哈! 问题和步骤: 1. Xshell 过期了,修改用Free for Home/School版本,https:// ...
- monggo查询语法
db.getCollection('vvt_user_reward').find({"description":"双节活动"})
- Vue项目打包报错Failed to load resource: net::ERR_FILE_NOT_FOUND
webpack.prod.conf.js 中output添加参数publicPath:'./' 修改webpack.base.conf.js中: publicPath: process.env.NOD ...
- OpenGL学习--06--键盘与鼠标交互
1.tutorial06.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...
- java实现Kafka的消费者示例
使用java实现Kafka的消费者 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
- INFO: Font Metrics and the Use of Negative lfHeight
INFO: Font Metrics and the Use of Negative lfHeight Print Email Article translations Article ID ...
- mysql使用笔记(网易Mysql实用手册)---1
1帮助使用 1.1按层次查看帮助 1 当不知道帮助可提供什么时,可通过MySQL内置帮助文档,一层层往下看. 命令: mysql> ? contents ? 等效help,该文档涵盖了数据库操作 ...