码迷,mamicode.com
首页 > Web开发 > 详细

elasticsearch CURL命令

时间:2017-11-19 15:39:15      阅读:496      评论:0      收藏:0      [点我收藏+]

标签:bing   pos   post   first   ocs   执行   get post   实现   pretty   

后台启动elasticsearch
elasticsearch-2.2.0/bin/elasticsearch -d
启动kibana(便于Web端进行查看)
kibana-4.4.1-linux-x64/bin/kibana


CURL命令
– 简单认为是可以在命令行下访问url的一个工具
– curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用
curl可以简单实现常见的get/post请求。
– curl
– -x 指定http请求的方法
– HEAD GET POST PUT DELETE
– -d 指定要传输的数据

建立索引库:
curl -XPOST http://localhost:9200/bjsxt
索引库名称必须要全部小写,不能以下划线开头,也不能包含逗号

创建索引:
curl -XPOST http://localhost:9200/bjsxt/employee/1 -d
‘{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}‘

如果想要确定我们创建的都是全新的内容,使用?op_type=create、_create
curl -XPUT http://localhost:9200/bjsxt/emp/2?op_type=create -d ‘{"name":“zs","age":25}‘
curl -XPUT http://localhost:9200/bjsxt/emp/2/_create -d ‘{"name":“laoxiao","age":25}‘
返回201 Created/409 Conflict

根据员工id查询:
curl -XGET http://localhost:9200/bjsxt/employee/1?pretty
curl后添加-i 参数,就能得到反馈头文件
curl -i ‘http://localhost:9200/bjsxt/employee/1?pretty‘
在任意的查询字符串中添加pretty参数,es可以得到易于识别的json结果

GET查询索引
检索文档中的一部分,只显示name,age字段
curl -XGET http://localhost:9200/bjsxt/employee/1?_source=name,age
如果只需要source的数据
curl -XGET http://localhost:9200/bjsxt/employee/1/_source
查询所有
curl -XGET http://localhost:9200/bjsxt/employee/_search
根据条件进行查询
curl -XGET http://localhost:9200/bjsxt/employee/_search?q=last_name:Smith

使用mget API获取多个文档
curl -XGET http://localhost:9200/_mget?pretty -d ‘{
"docs":[{
"_index":"bjsxt",
"_type":"emp",
"_id":2,
"_source":"name"
},{
"_index":"website",
"_type":"blog",
"_id":2
}]}‘

如果只想检查一下文档是否存在,你可以使用HEAD来替代GET方法,这样就只会返回HTTP头文件:
curl -i -XHEAD http://localhost:9200/bjsxt/employee/1

Elasticsearch的版本控制
首先得到需要修改的文档,获取版本(_version)号
curl -XGET http://localhost:9200/bjsxt/employee/1
在执行更新操作的时候把版本号传过去
curl -XPUT http://localhost:9200/bjsxt/employee/1?version=2 -d ‘{"name":"zs","age":25}‘
(覆盖)
curl -XPOST http://localhost:9200/bjsxt/employee/1/_update?version=3 -d ‘{"doc":{"city":"beijing","car":"BMW"}}‘
(部分更新)

elasticsearch CURL命令

标签:bing   pos   post   first   ocs   执行   get post   实现   pretty   

原文地址:http://www.cnblogs.com/mycd/p/7859792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!