收藏 分销(赏)

ElasticSearch简单使用手册.docx

上传人:丰**** 文档编号:3016627 上传时间:2024-06-13 格式:DOCX 页数:12 大小:114.63KB
下载 相关 举报
ElasticSearch简单使用手册.docx_第1页
第1页 / 共12页
ElasticSearch简单使用手册.docx_第2页
第2页 / 共12页
ElasticSearch简单使用手册.docx_第3页
第3页 / 共12页
ElasticSearch简单使用手册.docx_第4页
第4页 / 共12页
ElasticSearch简单使用手册.docx_第5页
第5页 / 共12页
点击查看更多>>
资源描述

1、Elasticsearch简单使用手册1.Win7系统下安装ES1.1ES的安装从官网上下载最新版本的ES,本次使用的是elasticsearch-5.5.0版本网址是https:/www.elastic.co/downloads/elasticsearch解压缩,执行elasticsearch-5.5.0bin下面的elasticsearch.bat即可在浏览器中输入http:/localhost:9200,出现如下界面表示运行成功1.2安装elasticsearch-head插件(非必须)这个安装比较复杂,首先确保本地计算机安装有git和nodejs,npmStep1:将elasticse

2、arch-head 从github上面clone下来。具体操作如下,git clone git:/Step2:修改elasticsearch-head/Gruntfile.js文件,增加hostname属性,设置为本地路径(127.0.0.1)或者*(代表任意)Step3: 修改elasticsearch-head /_site/app.js文件修改head的连接地址:this.base_uri = this.config.base_uri | this.prefs.get(app-base_uri) | http:/localhost:9200;把localhost修改成你es的服务器地址,

3、如:this.base_uri = this.config.base_uri | this.prefs.get(app-base_uri) | http:/10.10.10.10:9200;Step4:文件目录elasticsearch-5.5.0 /config/elasticsearch.yml, 修改Elasticsearch的参数,注意,设置参数的时候:后面要有空格!# 增加新的参数,这样head插件可以访问eshttp.cors.enabled: true http.cors.allow-origin: * Step5:安装grunt,命令如下npm install -g grunt

4、-cliStep6:在elasticsearch-head目录下执行npm install 下载elasticsearch-head运行的依赖包Step7:运行grunt server启动服务Step8:访问http:/localhost:9100/,出现如下界面表示安装成功2.Linux系统下集群部署ES2.1机器配置三台Linux虚拟机,安装系统CentOS6.5对应静态IP分别为192.168.244.128, 192.168.244.129,192.168.244.130开放9200和9300端口,步骤如下:#/sbin/iptables -I INPUT -p tcp -dport

5、9200 -j ACCEPT#/sbin/iptables -I INPUT -p tcp -dport 9300 -j ACCEPT然后保存:#/etc/rc.d/init.d/iptables save查看打开的端口:# /etc/init.d/iptables status2.2安装步骤Step1:从官网上下载ElasticSearch的tar包,本次使用版本5.5.1。分别上传到三台机器中Step2:解压tar包,修改elasticsearch-5.5.1/config路径下的elasticsearch.yml 配置文件。主要修改如下几个配置项:#设置集群的名称,三台机器要一样clus

6、ter.name: my-application#设置各节点名称node.name: node-128#数据存储的位置path.data: /home/hous/develop/elasticsearch-data/data#日志存储的位置path.logs: /home/hous/develop/elasticsearch-data/logs#内存锁定,即不使用linux中的交换内存(swap)bootstrap.memory_lock: true#检查是否支持SecComp模式运行,centos6.x不支持bootstrap.system_call_filter: false#绑定本机IP

7、地址network.host: 192.168.244.128#设置访问端口http.port: 9200#以单播方式嗅探集群中的机器discovery.zen.ping.unicast.hosts: 192.168.244.128, 192.168.244.129, 192.168.244.130#防止脑裂(节点数/2+1得出)discovery.zen.minimum_master_nodes: 2#支持跨域http.cors.enabled: truehttp.cors.allow-origin: *Step3:分别启动elasticsearch,进入elasticsearch-5.5.

8、1/bin路径下,运行命令:./elasticsearch或者后台启动命令:./ elasticsearch d启动完毕后,可以输入curl 192.168.244.128:9200/_cluster/health?pretty查看集群健康状态,显示为green表示正常启动2.3常见问题问题一WARN o.e.b.JNANatives unable to install syscall filter:Java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SEC

9、COMPandCONFIG_SECCOMP_FILTERcompiledinatorg.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) elasticsearch-5.5.1.jar:5.5.1at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) elasticsearch-5.5.1.jar:5.5.1原因:报了一大串错误,大家不必惊慌,其实只是一个警告,主要是因为你Linux版本过低造成的解决方案:1、重新安装新版本的Linux系统2、警告不影响使用

10、,可以忽略问题二ERROR: bootstrap checks failedmax file descriptors 4096 for elasticsearch process likely too low, increase to at least 65536原因:无法创建本地文件问题,用户最大可创建文件数太小解决方案:切换到root用户,编辑limits.conf配置文件vi /etc/security/limits.conf添加如下内容:* soft nofile 65536* hard nofile 131072* soft nproc 2048* hard nproc 4096备注

11、:* 代表Linux所有用户名称(比如 hadoop)保存、退出、重新登录才可生效问题三max number of threads 1024 for user es likely too low, increase to at least 2048原因:无法创建本地线程问题,用户最大可创建线程数太小解决方案:切换到root用户,进入limits.d目录下修改90-nproc.conf 配置文件vi /etc/security/limits.d/90-nproc.conf找到如下内容:* soft nproc 1024#修改为* soft nproc 2048问题四max virtual mem

12、ory areas vm.max_map_count 65530 likely too low, increase to at least 262144原因:最大虚拟内存太小解决方案:切换到root用户下,修改配置文件sysctl.confvi /etc/sysctl.conf添加下面配置:vm.max_map_count=655360并执行命令:sysctl -p然后重新启动elasticsearch,即可启动成功问题五ElasticSearch启动找不到主机或路由原因:ElasticSearch 单播配置有问题解决方案:检查ElasticSearch中的配置文件vi config/elas

13、ticsearch.yml找到如下配置:discovery.zen.ping.unicast.hosts:192.168.*.*:9300,192.168.*.*:9300一般情况下,是这里配置有问题,注意书写格式问题六org.elasticsearch.transport.RemoteTransportException: Failed to deserialize exception response from stream原因:ElasticSearch节点之间的jdk版本不一致解决方案:ElasticSearch集群统一jdk环境问题七Unsupported major.minor v

14、ersion 52.0原因:jdk版本问题太低解决方案:更换jdk版本,ElasticSearch5.0.0支持jdk1.8.0问题八can not run elasticsearch as root原因:不能以root用户启动ES服务器。解决方案:非要以root用户运行,则配置-Des.insecure.allow.root=true对于5.X,在config/jvm.options配置文件中,添加-Des.insecure.allow.root=true问题九memory locking requested for elasticsearch process but memory is n

15、ot locked解决方法1:配置 config/elasticsearch.yml ,注释掉以下内容#bootstrap.memory_lock: true解决方法2:配置:/etc/security/limits.conf,* soft memlock unlimited* hard memlock unlimited 3.Elasticsearch相关概念解释对比与关系型数据库,ES的各种概念确实不好理解。尤其对“索引”二字更是与关系型数据库混淆的不行,下面通过与MySQL简单对比,加深理解以上表为依据,在ES中的新建文档(在Index/type下)相当于mysql中(在某Databas

16、e的Table)下插入一行数据。4.安装中文分词器1. 中文分词器的安装中文分词器ik具体安装步骤如下拼音分词器的安装步骤如下2. java创建索引是添加分词器5.关于字符串的一些说明在ES中,字符串的类型有两种,分别是text和keyword。他们的区别是,text可以进行analyzed分词操作。keyword不可以not_analyzed。下图是对name字符串的属性说明1)表示使用ik_smart中文分词2)表示字符串类型为text,可以进行分词3)ignore_above是索引的范围,用于not_analyzed字段,默认不会对20字节的数据索引,如果要存储超过32766字节的数据,

17、设置ignore_above=256就可以了4)表示字符串类型为keyword,不可以进行分词总体说明:name是text类型,用ik_smart分词倒排索引。name.keyword是keyword类型不可以分词,存储超过32766字节6.通过CURL操作的简单命令下面以索引名my_index,索引类型my_type为例进行说明6.1创建索引创建一个空索引,索引名为my_indexcurl -XPUT 192.168.244.1:9200/my_index -d 6.2添加mapping添加索引类型,包括字段类型curl -XPUT 192.168.244.1:9200/my_index/_

18、mapping/my_type -d properties: name: analyzer: ik_smart, type: text, fields: keyword: ignore_above: 256, type: keyword , id: type: long , age: type: integer , desc: analyzer: ik_smart, type: text, fields: keyword: ignore_above: 256, type: keyword 6.3添加文档数据添加一条文档数据curl -XPOST 192.168.244.1:9200/my_in

19、dex/my_type -d id: 1, name: 张小明, desc: java工程师,从事大数据软件开发, age: 23批量添加文档数据,这种格式类似一个有效的单行JSON文档流,它通过换行符(n)连接到一起。注意两个要点:l 每行一定要以换行符(n)结尾, 包括最后一行 。这些换行符被用作一个标记,可以有效分隔行。l 这些行不能包含未转义的换行符,因为他们将会对解析造成干扰。curl -XPOST 192.168.244.1:9200/_bulk -d index: _index: my_index, _type: my_type id:5,name:张三丰,desc:java工程

20、师,从事大数据软件开发,对nosql数据库有研究,age:123 index: _index: my_index, _type: my_type id:2,name:jack,desc:php工程师,从事网站开发,对java也有一定了解,age:30 index: _index: my_index, _type: my_type id:3,name:李晓红,desc:前端工程师,对react,angularjs有研究,age:22 index: _index: my_index, _type: my_type id:4,name:王晓燕,desc:UI设计师,目前处于实现阶段,age:19 i

21、ndex: _index: my_index, _type: my_type id:6,name:jannes,desc:数据库工程师,对oracle和mysql有一定的经验,age:356.4删除文档数据删除一条文档数据curl -XDELETE 192.168.244.1:9200/my_index/my_type/AV3E0qBK9W2J9WuRt8D3删除多条文档数据curl -XPOST 192.168.244.1:9200/_bulk -d delete: _index: my_index, _type: my_type, _id: AV3E0qBK9W2J9WuRt8D4 del

22、ete: _index: my_index, _type: my_type, _id: AV3E0qBK9W2J9WuRt8D5 delete: _index: my_index, _type: my_type, _id: AV3E0qBK9W2J9WuRt8D6 delete: _index: my_index, _type: my_type, _id: AV3E0qBK9W2J9WuRt8D7 delete: _index: my_index, _type: my_type, _id: AV3BQz3xJ5KYRov5JoNA 6.5查询文档数据wildcard通配符查询curl -XGE

23、T 192.168.244.128:9200/my_index8/my_type8/_search -d query: wildcard: name.keyword: 张* term精确查询curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query: term: desc: 工程师 terms查找多个精确值curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query: terms: age: 22,23 range范围查询range查询可同时提供

24、包含(inclusive)和不包含(exclusive)这两种范围表达式,可供组合的选项如下:gt:大于(greater than)lt:=大于或等于(greater than or equal to)lte:=小于或等于(less than or equal to)curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query : constant_score : filter : range : age : gte : 20, lt : 40 exists查询和not exists(missing查询过时被删除) (n

25、ull and not null)curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query : exists : field : desc curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query: bool: must_not: exists: field: desc Bool Query组合查询bool查询由以下元素组成,分别是must,filter,should,must_notmust:所有的语句都必须(must)匹配,与AND等价

26、must_not:所有的语句都不能(must not)匹配,与NOT等价should:至少有一个语句要匹配,与OR等价filter:过滤器查询,忽略scoreboost增加相关度评分比重_score, minimum_should_matchPOST _search query: bool : must : term : user : kimchy , filter: term : tag : tech , must_not : range : age : gte : 10, lte : 20 , should : term : tag : wow , term : tag : elastic

27、search , minimum_should_match : 1, boost : 1.0 curl -XGET 192.168.244.128:9200/my_index8/my_type8/_search -d query: bool : must : term : desc : 工程师 , filter: term : name : 张三丰 , must_not : range : age : gte : 0, lte : 20 , should : term : name : 晓 , term : desc : java , minimum_should_match : 1, boo

28、st : 1.0 match匹配查询operator默认or,可以为and,表示满足所有分词条件curl -XGET 192.168.244.130:9200/my_index8/my_type8/_search -d query: match: desc: query: java工程师数据软件开发, operator: and 相邻单词查询,slop相邻的单词个数curl -XGET 192.168.244.130:9200/my_index8/my_type8/_search -d query: match_phrase: desc: query: jjava工程师, slop: 1 Multi Match Query可以添加type查询参数:best_fields,most_fields,cross_fields,phrase,phrase_prefixcurl -XGET 192.168.244.130:9200/my_index8/my_type8/_search -d query: multi_match : query: 软件开发, fields: name, desc

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服