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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,402评论 6 499
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,377评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,483评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,165评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,176评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,146评论 1 297
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,032评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,896评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,311评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,536评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,696评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,413评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,008评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,659评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,815评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,698评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,592评论 2 353

推荐阅读更多精彩内容