欢迎投稿

今日深度:

es 一 ---,es---

es 一 ---,es---


环境:

系统:centos6.4

elasticsearch:1.5.2

ik:1.5

 

1.安装elasticsearch

[html] view plain copy
  1. curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.5.2.tar.gz  
  2. tar -xvf elasticsearch-1.5.2.tar.gz  
  3. cd elasticsearch-1.5.2/bin  

2.elasticsearch插件安装

elasticsearch-koaf  通过koaf,可以查看集群几乎所有信息,还能进行简单的搜索查询,观察自动恢复的情况等等。

安装完成之后,在浏览器输入:http://192.168.199.159:9200/_plugin/kopf ,可以查看显示效果

 

**一定是bin的上级目录执行,要有bin/plugin


[html] view plain copy
  1. ./elasticsearch/bin/plugin --install lmenezes/elasticsearch-kopf/1.5.4  

3.安装ik分词

https://github.com/medcl/elasticsearch-analysis-ik

http://davidbj.blog.51cto.com/4159484/1604393

编译源码成zip压缩包

elasticsearch-analysis-ik-1.3.0.zip


[html] view plain copy
  1. `git clone https://github.com/medcl/elasticsearch-analysis-ik`  
  2. `cd elasticsearch-analysis-ik`  
  3. `mvn compile`  
  4. `mvn package`  

在elasticsearch/plugins目录下创建目录analysis_ik

[html] view plain copy
  1. cd elasticsearch-1.5.2/plugins  
  2. mkdir analysis-ik  
  3. cd analysis-ik  
  4. unzip elasticsearch-analysis-ik-1.3.0.zip  
  5. rm elasticsearch-analysis-ik-1.3.0.zip  

https://github.com/davidbj/elasticsearch-rtf/archive/master.zip unzip master.zip 将master的解压目录config/ik文件夹压缩成zip 复制到elasticsearch-1.5.2/config目录下 [html] view plain copy
  1. cd elasticsearch-1.5.2/config  
  2. unzip ik.zip  
  3. rm ik.zip  

配置elasticsearch.yml的分词


[html] view plain copy
  1. vim elasticsearch.yml  
  2.    
  3. cluster.name: boluofan   
  4.    
  5. index:  
  6.   analysis:                     
  7.     analyzer:        
  8.       ik:  
  9.           alias: [ik_analyzer]  
  10.           type: org.elasticsearch.index.analysis.IkAnalyzerProvider  
  11.       ik_max_word:  
  12.           type: ik  
  13.           use_smart: false  
  14.       ik_smart:  
  15.           type: ik  
  16.           use_smart: true  
  17.    


4.启动 & 关闭   -d  后台运行   -p  pid的文件位置


[html] view plain copy
  1. ./elasticsearch -d -p /tmp/es.pid  
  2. kill `cat /tmp/es.pid`  

***如果只启动一个实例的话,那么es只会启动 主分片,不会启动 复制分片,这种情况下可以使用 下列指令查看status是yellow状态的,这就说明不会启动 复制分片


[html] view plain copy
  1. curl -i -XGET 'http://localhost:9200/_cluster/health'  

[html] view plain copy
  1. status字段提供一个综合的指标来表示集群的的服务状况。三种颜色各自的含义:  


   颜色         意义 
green 所有主要分片和复制分片都可用
red 不是所有的主要分片都可用
yellow 所有主要分片可用,但不是所有复制分片都可用

***想要启动复制分片的方法很简单,只需要直接再启动一次,不管是在本地机器还是另一个ip的机器上

    只要第二个节点与第一个节点有相同的cluster.name(请看./config/elasticsearch.yml文件),它就能自动发现并加入第一个节点所在的集群。

    如果没有,检查日志找出哪里出了问题。这可能是网络广播被禁用,或者防火墙阻止了节点通信。



[html] view plain copy
  1. ./elasticsearch -d -p /tmp/es_share.pid  


**这个时候再使用命令查看es的健康状态。就会发现status变成green

[html] view plain copy
  1. curl -i -XGET 'http://localhost:9200/_cluster/health'  


5.es概念,具体参考elasticsearch权威指南:http://es.xiaoleilu.com/010_Intro/25_Tutorial_Indexing.html

[html] view plain copy
  1. Index  
  2. 可以把 ElasticSearch 的 Index 理解为 MySQL 的一个数据库。  
  3. Type  
  4. 可以理解为 MySQL 中的一个表  
  5. Document  
  6. ElasticSearch 中的一个 document 相当于 MySQL 某个表中的一条记录。它是 JSON 结构。  
  7.    
  8. Mapping  
  9. 可以理解为 MySQL 的表结构(table schema)  
  10. Cluster  
  11. 很多个 ElasticSearch 的节点(node)可以构成一个分布式的集群(cluster)。  
  12. Shard  
  13. 每个 index 的数据默认切分到 5 个 shards 中。  
  14. 有点像 MongoDB,也有点像 MySQL 表的水平分割。  


6.测试: 1.创建索引 [html] view plain copy
  1. curl -XPUT http://localhost:9200/index  

2.创建type映射

[html] view plain copy
  1. curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'  
  2. {  
  3.     "fulltext": {  
  4.              "_all": {  
  5.             "indexAnalyzer": "ik",  
  6.             "searchAnalyzer": "ik",  
  7.             "term_vector": "no",  
  8.             "store": "false"  
  9.         },  
  10.         "properties": {  
  11.             "content": {  
  12.                 "type": "string",  
  13.                 "store": "no",  
  14.                 "term_vector": "with_positions_offsets",  
  15.                 "indexAnalyzer": "ik",  
  16.                 "searchAnalyzer": "ik",  
  17.                 "include_in_all": "true",  
  18.                 "boost": 8  
  19.             }  
  20.         }  
  21.     }  
  22. }'  

3.创建索引记录document

[html] view plain copy
  1. curl -XPOST http://localhost:9200/index/fulltext/1 -d'  
  2. {"content":"美国留给伊拉克的是个烂摊子吗"}  
  3. '  
  4.    
  5. curl -XPOST http://localhost:9200/index/fulltext/2 -d'  
  6. {"content":"公安部:各地校车将享最高路权"}  
  7. '  
  8.    
  9. curl -XPOST http://localhost:9200/index/fulltext/3 -d'  
  10. {"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}  
  11. '  
  12.    
  13. curl -XPOST http://localhost:9200/index/fulltext/4 -d'  
  14. {"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}  
  15. '  

4.查询并且高亮关键字

[html] view plain copy
  1. curl -XPOST http://localhost:9200/index/fulltext/_search  -d'  
  2. {  
  3.     "query" : { "term" : { "content" : "中国" }},  
  4.     "highlight" : {  
  5.         "pre_tags" : ["<tag1>", "<tag2>"],  
  6.         "post_tags" : ["</tag1>", "</tag2>"],  
  7.         "fields" : {  
  8.             "content" : {}  
  9.         }  
  10.     }  
  11. }  
  12. '  

5。查询结果

[html] view plain copy
  1. {  
  2.     "took": 14,  
  3.     "timed_out": false,  
  4.     "_shards": {  
  5.         "total": 5,  
  6.         "successful": 5,  
  7.         "failed": 0  
  8.     },  
  9.     "hits": {  
  10.         "total": 2,  
  11.         "max_score": 2,  
  12.         "hits": [  
  13.             {  
  14.                 "_index": "index",  
  15.                 "_type": "fulltext",  
  16.                 "_id": "4",  
  17.                 "_score": 2,  
  18.                 "_source": {  
  19.                     "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"  
  20.                 },  
  21.                 "highlight": {  
  22.                     "content": [  
  23.                         "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "  
  24.                     ]  
  25.                 }  
  26.             },  
  27.             {  
  28.                 "_index": "index",  
  29.                 "_type": "fulltext",  
  30.                 "_id": "3",  
  31.                 "_score": 2,  
  32.                 "_source": {  
  33.                     "content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"  
  34.                 },  
  35.                 "highlight": {  
  36.                     "content": [  
  37.                         "均每天扣1艘<tag1>中国</tag1>渔船 "  
  38.                     ]  
  39.                 }  
  40.             }  
  41.         ]  
  42.     }  
  43. }  

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/29238.html NewsArticle es 一 ---,es--- 环境: 系统:centos6.4 elasticsearch:1.5.2 ik:1.5   1.安装elasticsearch [html] view plain copy curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.5.2.tar.gz   tar -xvf elast...
相关文章
    暂无相关文章
评论暂时关闭