ElasticSearch简单使用手册.docx_第1页
ElasticSearch简单使用手册.docx_第2页
ElasticSearch简单使用手册.docx_第3页
ElasticSearch简单使用手册.docx_第4页
ElasticSearch简单使用手册.docx_第5页
免费预览已结束,剩余7页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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:将elasticsearch-head 从github上面clone下来。具体操作如下,git clone git://mobz/elasticsearch-head.gitStep2:修改elasticsearch-head/Gruntfile.js文件,增加hostname属性,设置为本地路径()或者*(代表任意)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的服务器地址,如:this.base_uri = this.config.base_uri | this.prefs.get(app-base_uri) | 0: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-cliStep6:在elasticsearch-head目录下执行npm install 下载elasticsearch-head运行的依赖包Step7:运行grunt server启动服务Step8:访问http:/localhost:9100/,出现如下界面表示安装成功2.Linux系统下集群部署ES2.1机器配置三台Linux虚拟机,安装系统CentOS6.5对应静态IP分别为28, 29,30开放9200和9300端口,步骤如下:#/sbin/iptables -I INPUT -p tcp -dport 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 配置文件。主要修改如下几个配置项:#设置集群的名称,三台机器要一样: my-application#设置各节点名称: 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地址network.host: 28#设置访问端口http.port: 9200#以单播方式嗅探集群中的机器discovery.zen.ping.unicast.hosts: 28, 29, 30#防止脑裂(节点数/2+1得出)discovery.zen.minimum_master_nodes: 2#支持跨域http.cors.enabled: truehttp.cors.allow-origin: *Step3:分别启动elasticsearch,进入elasticsearch-5.5.1/bin路径下,运行命令:./elasticsearch或者后台启动命令:./ elasticsearch d启动完毕后,可以输入curl 28: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_SECCOMPandCONFIG_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、警告不影响使用,可以忽略问题二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备注:* 代表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 memory 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/elasticsearch.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 version 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 not 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中(在某Database的Table)下插入一行数据。4.安装中文分词器1. 中文分词器的安装中文分词器ik具体安装步骤如下/medcl/elasticsearch-analysis-ik/拼音分词器的安装步骤如下/medcl/elasticsearch-analysis-pinyin/2. java创建索引是添加分词器5.关于字符串的一些说明在ES中,字符串的类型有两种,分别是text和keyword。他们的区别是,text可以进行analyzed分词操作。keyword不可以not_analyzed。下图是对name字符串的属性说明1)表示使用ik_smart中文分词2)表示字符串类型为text,可以进行分词3)ignore_above是索引的范围,用于not_analyzed字段,默认不会对20字节的数据索引,如果要存储超过32766字节的数据,设置ignore_above=256就可以了4)表示字符串类型为keyword,不可以进行分词总体说明:name是text类型,用ik_smart分词倒排索引。name.keyword是keyword类型不可以分词,存储超过32766字节6.通过CURL操作的简单命令下面以索引名my_index,索引类型my_type为例进行说明6.1创建索引创建一个空索引,索引名为my_indexcurl -XPUT :9200/my_index -d 6.2添加mapping添加索引类型,包括字段类型curl -XPUT :9200/my_index/_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 :9200/my_index/my_type -d id: 1, name: 张小明, desc: java工程师,从事大数据软件开发, age: 23批量添加文档数据,这种格式类似一个有效的单行JSON文档流,它通过换行符(n)连接到一起。注意两个要点:l 每行一定要以换行符(n)结尾, 包括最后一行 。这些换行符被用作一个标记,可以有效分隔行。l 这些行不能包含未转义的换行符,因为他们将会对解析造成干扰。curl -XPOST :9200/_bulk -d index: _index: my_index, _type: my_type id:5,name:张三丰,desc:java工程师,从事大数据软件开发,对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 index: _index: my_index, _type: my_type id:6,name:jannes,desc:数据库工程师,对oracle和mysql有一定的经验,age:356.4删除文档数据删除一条文档数据curl -XDELETE :9200/my_index/my_type/AV3E0qBK9W2J9WuRt8D3删除多条文档数据curl -XPOST :9200/_bulk -d delete: _index: my_index, _type: my_type, _id: AV3E0qBK9W2J9WuRt8D4 delete: _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 -XGET 28:9200/my_index8/my_type8/_search -d query: wildcard: name.keyword: 张* term精确查询curl -XGET 28:9200/my_index8/my_type8/_search -d query: term: desc: 工程师 terms查找多个精确值curl -XGET 28:9200/my_index8/my_type8/_search -d query: terms: age: 22,23 range范围查询range查询可同时提供包含(inclusive)和不包含(exclusive)这两种范围表达式,可供组合的选项如下:gt:大于(greater than)lt:=大于或等于(greater than or equal to)lte:=小于或等于(less than or equal to)curl -XGET 28:9200/my_index8/my_type8/_search -d query : constant_score : filter : range : age : gte : 20, lt : 40 exists查询和not exists(missing查询过时被删除) (null and not null)curl -XGET 28:9200/my_index8/my_type8/_search -d query : exists : field : desc curl -XGET 28:9200/my_index8/my_type8/_search -d query: bool: must_not: exists: field: desc Bool Query组合查询bool查询由以下元素组成,分别是must,filter,should,must_notmust:所有的语句都必须(must)匹配,与AND等价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 : a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论