elasticsearch安装试用

elasticsearch是一个基于Lucene构建的开源,分布式,Restful搜索引擎,支持Http使用JSON进行数据索引,下面简单试用。

首先下载(我选择的版本是0.19.9),解压后运行(执行bin/elasticsearch)

一,插入索引

curl -XPUT 'http://localhost:9200/addressbook/friends/1' -d '{
> "name":"stone",
> "tel":"1234567"
> }'
{"ok":true,"_index":"addressbook","_type":"friends","_id":"1","_version":1}

或者通过制定operation type的方式插入索引(uri的风格还有其他方式,可以参照官方介绍)

curl -XPUT 'http://localhost:9200/addressbook/friends/2?op_type=create' 
> "name":"penjin",
> "tel":"2345678"
> }'
{"ok":true,"_index":"addressbook","_type":"friends","_id":"2","_version":1}

二,查找索引

curl -XGET 'http://localhost:9200/addressbook/friends/1'
{"_index":"addressbook","_type":"friends","_id":"1","_version":1,"exists":true, "_source" : {
"name":"stone",
"tel":"1234567"
}}
查找索引时指定返回的域
curl -XGET 'http://localhost:9200/addressbook/friends/2?fields=tel'
{"_index":"addressbook","_type":"friends","_id":"2","_version":1,"exists":true,"fields":{"tel":"2345678"}}
查找不存在的索引返回错误

curl -XGET 'http://localhost:9200/addressbook/friends/3'
{"_index":"addressbook","_type":"friends","_id":"3","exists":false}
一次查询返回多个结果(具体还可以设置返回指定域)

curl 'localhost:9200/addressbook/friends/_mget' -d '{
> "ids":["1","2"]
> }'
{"docs":[{"_index":"addressbook","_type":"friends","_id":"1","_version":1,"exists":true, "_source" : {
"name":"stone",
"tel":"1234567"
}},{"_index":"addressbook","_type":"friends","_id":"2","_version":1,"exists":true, "_source" : {
"name":"penjin",
"tel":"2345678"
}}]}
三,搜索(可指定搜索条件,搜索范围,结果排序等,示例如下)
curl -XGET 'http://localhost:9200/addressbook/friends/_search' -d '{
> "query":{
>   "term" : {"name":"penjin"}
> }
> }'
{"took":262,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"addressbook","_type":"friends","_id":"2","_score":0.30685282, "_source" : {
"name":"penjin",
"tel":"2345678"
}}]}}
四,删除索引(还可指定删除条件等)

curl -XDELETE 'http://localhost:9200/addressbook/friends/1'
{"ok":true,"found":true,"_index":"addressbook","_type":"friends","_id":"1","_version":2}

elasticsearch是一个分布式的搜索引擎,具体使用上如何分片,集群等,以后有项目做时再深入了解,感觉用来做点日志分析挺不错的。

更多大牛的专栏资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值