ubuntu 16 安装Elasticsearch

1. 下载

cd /opt
sudo wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.5/elasticsearch-2.3.5.tar.gz

2.解压

sudo tar zxvf elasticsearch-2.3.5.tar.gz

3.启动

cd elasticsearch
bin/elasticsearch -d
修改配置:
# ---------------------------------- Cluster --------------------
#
# Use a descriptive name for your cluster:
#
 cluster.name: my-application
#
# ------------------------------------ Node -------------------
#
# Use a descriptive name for the node:
#
 node.name: node-1

4.访问

curl -i 'http://localhost:9200/?pretty'

{
    "name" : "Jekyll",
    "cluster_name" : "elasticsearch",
    "version" : {
        "number" : "2.3.5",
        "build_hash" : "90f439ff60a3c0f497f91663701e64ccd01edbb4",
        "build_timestamp" : "2016-07-27T10:36:52Z",
        "build_snapshot" : false,
        "lucene_version" : "5.5.0"
    },
    "tagline" : "You Know, for Search"
}

5. 安装head插件

bin/plugin install mobz/elasticsearch-head
http://localhost:9200/_plugin/head/
Paste_Image.png

6. 安装并启动kibana插件

sudo wget  https://download.elastic.co/kibana/kibana/kibana-4.5.4-linux-x64.tar.gz
sudo tar zxvf kibana-4.5.4-linux-x64.tar.gz
cd kibana-4.5.4-linux-x64
bin/kibana &

7. 安装监控marvel

sudo wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/license/2.3.5/license-2.3.5.zip
sudo wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/marvel-agent/2.3.5/marvel-agent-2.3.5.zip
sudo wget https://download.elasticsearch.org/elasticsearch/marvel/marvel-2.3.5.tar.gz

bin/plugin install file:///opt/license-2.3.5.zip
bin/plugin install file:///opt/marvel-agent-2.3.5.zip
bin/kibana plugin --install marvel --url file:///opt/marvel-2.3.5.tar.gz

curl http://localhost:5601/
Paste_Image.png
Paste_Image.png
官网插件安装地址
https://www.elastic.co/guide/en/marvel/2.3/installing-marvel.html     
Screenshot.png

8.健康检查

curl 'localhost:9200/_cat/health?v'
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 
1471493855 12:17:35  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0% 

9.查询节点

curl 'localhost:9200/_cat/nodes?v'
host      ip        heap.percent ram.percent load node.role master name   
127.0.0.1 127.0.0.1            3          87 0.35 d         *      Jekyll 

10. list all indices

curl 'localhost:9200/_cat/indices?v'
health status index   pri rep docs.count docs.deleted store.size pri.store.size 
yellow open   .kibana   1   1          2            0     19.1kb         19.1kb

11. shared

curl 'localhost:9200/_cat/shards?v'
index   shard prirep state      docs  store ip        node   
.kibana 0     p      STARTED       2 19.1kb 127.0.0.1 Jekyll 
.kibana 0     r      UNASSIGNED 

12.按照中文分词插件

./bin/plugin install medcl/elasticsearch-rtf  

二、使用(请参考README文档)

1.角色关系对照elasticsearch 跟 MySQL 中定义资料格式的角色关系对照表如下
  MySQL                 elasticsearch     
  database              index                  
  table                 type                    
  table schema          mapping
  row                   document
  field                 field

2.创建索引,相当于数据库wechat
curl -XPUT 'http://localhost:9200/wechat/user/info'   -d '{ "name" : "wechatUserInformation" }'
返回:{"_index":"wechat","_type":"user","_id":"info","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}
说明:索引库: wechat  
         表: user 
     主键id: id
   默认版本: 1  
       字段: name 
     字段值: wechatUserInformation

3.创建表和提交数据
curl -XPUT   'http://localhost:9200/wechat/user/1' -d '{ "subscribe" : 1, "openid" : "oH-JmuL9-lcG9NmufCJ3pHoQtIGE", "nickname" : "涛涛江水", "language" : "zh_CN", "city" : "沈阳", "province" : "辽宁", "country" : "中国", "headimgurl" : "http://wx.qlogo.cn/mmopen/nh5KLO4GkfafDtujhPTVgedAJGgDbNiafQKUian6Xibk7pHAJL5ff05fOjc5EydreJbvcTcgTkaZia4jucgGibtsysMMTFALr5XJU/0", "subscribe_time" : 1468924074, "remark" : "", "groupid" : 0, "tagid_list" : [ ], "platId" : "FH1KH6EXUD", "gender" : 1, "seqId" : 5, "languageId" : 50, "countryId" : 2, "provinceId" : 11, "cityId" : 12, "realtime_countryId" : 2, "realtime_provinceId" : 1108, "realtime_cityId" : 1020, "real_time_country" : "中国", "real_time_province" : "辽宁省", "real_time_city" : "沈阳市" }'

返回:{"_index":"wechat","_type":"user","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

4 . 查看

curl -XGET   'http://localhost:9200/wechat/user/info?pretty=true'
返回:
{ "_index" : "twitter",  "_type" : "user",  "_id" : "kimchy",  "_version" : 1,  "found" : true,  "_source":{ "name" : "wechatUserInformation" }}

curl -XGET 'http://localhost:9200/wechat/_search?pretty=true' -d '{"query" : {"match" : {"city" : "沈阳" }}}'

5.支持中文全文检索

  参考:https://github.com/medcl/elasticsearch-analysis-ik
 在elasticsearch.yml 文件末尾增加
  index.analysis.analyzer.ik.type: ik

6.测试中文搜索
  
  curl -XPUT http://localhost:9200/userindex

  7 . create a mapping
curl -XPOST http://localhost:9200/userindex/fulltext/_mapping -d'{ "fulltext": { "_all": { "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "properties": { "content": { "type": "string", "store": "no", "term_vector": "with_positions_offsets", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "include_in_all": "true", "boost": 8 } } }}'

 8..index some docs

curl -XPOST http://localhost:9200/userindex/fulltext/1 -d'{"content":"美国留给伊拉克的是个烂摊子吗"}'

curl -XPOST http://localhost:9200/userindex/fulltext/2 -d'{"content":"公安部:各地校车将享最高路权"}'

curl -XPOST http://localhost:9200/userindex/fulltext/3 -d'{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'

curl -XPOST http://localhost:9200/userindex/fulltext/4 -d'{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'

9 .query with highlighting

curl -XPOST http://localhost:9200/userindex/fulltext/_search -d'{ "query" : { "term" : { "content" : "中国" }}, "highlight" : { "pre_tags" : ["<tag1>", "<tag2>"], "post_tags" : ["</tag1>", "</tag2>"], "fields" : { "content" : {} } }}'

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容