elasticsearch

原创
2014/04/30 14:54
阅读数 615

#Elasticsearch#

##下载安装##

##体验##

  1. 在解压目录运行:
 ./bin/elasticsearch
[2014-04-30 14:07:13,930][INFO ][node                     ] [Roma] version[1.1.1], pid[7262], build[f1585f0/2014-04-16T14:27:12Z]
[2014-04-30 14:07:13,931][INFO ][node                     ] [Roma] initializing ...
[2014-04-30 14:07:13,958][INFO ][plugins                  ] [Roma] loaded [], sites []
[2014-04-30 14:07:16,993][INFO ][node                     ] [Roma] initialized
[2014-04-30 14:07:16,993][INFO ][node                     ] [Roma] starting ...
[2014-04-30 14:07:17,211][INFO ][transport                ] [Roma] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.20.152:9300]}
[2014-04-30 14:07:20,294][INFO ][cluster.service          ] [Roma] new_master [Roma][HHJEbKWSSPWKb6fL7yl1bA][XXX(**主机名保密)][inet[/192.168.20.152:9300]], reason: zen-disco-join (elected_as_master)
[2014-04-30 14:07:20,374][INFO ][discovery                ] [Roma] elasticsearch/HHJEbKWSSPWKb6fL7yl1bA
[2014-04-30 14:07:20,420][INFO ][http                     ] [Roma] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.20.152:9200]}
[2014-04-30 14:07:20,463][INFO ][gateway                  ] [Roma] recovered [0] indices into cluster_state
[2014-04-30 14:07:20,465][INFO ][node                     ] [Roma] started

  1. 浏览器输入:http://localhost:9200/
{
  "status" : 200,
  "name" : "Roma",
  "version" : {
    "number" : "1.1.1",
    "build_hash" : "f1585f096d3f3985e73456debdc1a0745f512bbc",
    "build_timestamp" : "2014-04-16T14:27:12Z",
    "build_snapshot" : false,
    "lucene_version" : "4.7"
  },
  "tagline" : "You Know, for Search"
}

说明安装成功。

  1. 索引和检索
 //索引,单field
 curl -XPUT http://localhost:9200/twitter/user/kimchy -d '{"name":"Shay Banon"}'
{"_index":"twitter","_type":"user","_id":"kimchy","_version":1,"created":true} 

//索引,多field
 curl -XPUT http://localhost:9200/twitter/tweet/1 -d '{"user":"kimchy","post_date":"2014-04-12T13:13:00","message":"Trying out elasticsearch,so far so good?"}'
{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"created":true} 

//索引,url里面的id和上面不一样
 curl -XPUT http://localhost:9200/twitter/tweet/2 -d '{"user":"kimchy","post_date":"2014-05-12T13:13:00","message":"You know,for Search"}'
{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"created":true} 
 

//获取数据
 curl -XGET http://localhost:9200/twitter/tweet/2
{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"found":true, "_source" : {"user":"kimchy","post_date":"2014-05-12T13:13:00","message":"You know,for Search"}} 
 
 
 //lucence语法方式查询
 curl -XGET http://localhost:9200/twitter/tweet/_search?q=user:kimchy
{"took":68,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"twitter","_type":"tweet","_id":"2","_score":1.0, "_source" : {"user":"kimchy","post_date":"2014-05-12T13:13:00","message":"You know,for Search"}},{"_index":"twitter","_type":"tweet","_id":"1","_score":0.30685282, "_source" : {"user":"kimchy","post_date":"2014-04-12T13:13:00","message":"Trying out elasticsearch,so far so good?"}}]}} 
 
 
//query DSL 方式查询
 curl -XGET http://localhost:9200/twitter/tweet/_search -d '{"query":{"term":{"user":"kimchy"}}}'
{"took":6,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"twitter","_type":"tweet","_id":"2","_score":1.0, "_source" : {"user":"kimchy","post_date":"2014-05-12T13:13:00","message":"You know,for Search"}},{"_index":"twitter","_type":"tweet","_id":"1","_score":0.30685282, "_source" : {"user":"kimchy","post_date":"2014-04-12T13:13:00","message":"Trying out elasticsearch,so far so good?"}}]}} 
 
 
//query DSL 方式查询,结果美化
 curl -XGET http://localhost:9200/twitter/_search?pretty=true -d '{"query":{"range":{"post_date":{"from":"2001-10-01T10:00:00","to":"2014-12-10T10:20:20"}}}}'
{
  "took" : 19,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "twitter",
      "_type" : "tweet",
      "_id" : "2",
      "_score" : 1.0, "_source" : {"user":"kimchy","post_date":"2014-05-12T13:13:00","message":"You know,for Search"}
    }, {
      "_index" : "twitter",
      "_type" : "tweet",
      "_id" : "1",
      "_score" : 1.0, "_source" : {"user":"kimchy","post_date":"2014-04-12T13:13:00","message":"Trying out elasticsearch,so far so good?"}
    } ]
  }
}
 

##特点##

  • 模式自由(Schema Free)& 面向文档的(Document Oriented)
  • 模式映射(Schema Mapping)
  • 获取数据(Geting Some Data)
  • 搜索(Search)
  • 多租户(Multi Tanancy)
  • 设置(Settings)
  • 分布式(Distributed)
  • 冗灾恢复(Gateway)
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部