博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
elasticsearch Curl 基本操作
阅读量:4210 次
发布时间:2019-05-26

本文共 1977 字,大约阅读时间需要 6 分钟。

创建文档:

curl -X PUT “localhost:9200/website/blog/2” -H ‘Content-Type: application/json’ -d’
{
“title”: “My first blog entry”,
“text”: “Just trying this out…”,
“date”: “2014/01/01”
}
取回文档:
curl -X GET “localhost:9200/website/blog/123?pretty”
在请求的查询串参数中加上 pretty 参数, 正如前面的例子中看到的,这将会调用 Elasticsearch 的 pretty-print 功能,该功能 使得 JSON 响应体更加可读。但是, _source字段不能被格式化打印出来。相反,我们得到的 _source 字段中的 JSON 串,刚好是和我们传给它的一样。

返回文档的一部分:

curl -X GET “localhost:9200/website/blog/123?_source=title,text”

检查文档是不是存在:

curl -i -XHEAD

删除文档:

DELETE /website/blog/123

更新文档

curl -X POST “localhost:9200/website/blog/123/_update” -H ‘Content-Type: application/json’ -d’
{
“doc” : {
“tags” : [ “testing” ],
“views”: 0
}
}
使用脚本更新文档
curl -X POST “localhost:9200/website/blog/123/_update” -H ‘Content-Type: application/json’ -d’
{
“script” : “ctx._source.views+=1”
}
更新文档的字段可能不存在,使用upsert 关键字,并且具有初始化的值
curl -X POST “localhost:9200/website/blog/123/_update” -H ‘Content-Type: application/json’ -d’
{
“script” : “ctx._source.views+=1”,
“upsert”: {
“views”: 1
}
}
更新和冲突,使retry_on_conflict 多次尝试更新
curl -X POST “localhost:9200/website/blog/123/_update?retry_on_conflict=5” -H ‘Content-Type: application/json’ -d’
{
“script” : “ctx._source.views+=1”,
“upsert”: {
“views”: 0
}
}
取回多个文档
curl -X GET “localhost:9200/_mget” -H ‘Content-Type: application/json’ -d’
{
“docs” : [
{
“_index” : “website”,
“_type” : “blog”,
“_id” : 2
},
{
“_index” : “website”,
“_type” : “blog”,
“_id” : 1,
“_source”: “views”
}
]
}
代价较小的批量操作
curl -X POST “localhost:9200/_bulk” -H ‘Content-Type: application/json’ -d’
{ “delete”: { “_index”: “website”, “_type”: “blog”, “_id”: “1” }}
{ “create”: { “_index”: “website”, “_type”: “blog”, “_id”: “123” }}
{ “title”: “My first blog post” , “blog”: “测试内容,测试内容” }
{ “index”: { “_index”: “website”, “_type”: “blog” }}
{ “title”: “My second blog post” }
{ “update”: { “_index”: “website”, “_type”: “blog”, “_id”: “123”, “_retry_on_conflict” : 3} }
{ “doc” : {“title” : “My updated blog post”} }

转载地址:http://gbwmi.baihongyu.com/

你可能感兴趣的文章
SQL注入漏洞全接触--高级篇
查看>>
SQL注入法攻击一日通
查看>>
论文浅尝 | 通过共享表示和结构化预测进行事件和事件时序关系的联合抽取
查看>>
论文浅尝 | 融合多粒度信息和外部语言知识的中文关系抽取
查看>>
论文浅尝 | GMNN: Graph Markov Neural Networks
查看>>
廖雪峰Python教程 学习笔记3 hello.py
查看>>
从内核看epoll的实现(基于5.9.9)
查看>>
python与正则表达式
查看>>
安装.Net Framework 4.7.2时出现“不受信任提供程序信任的根证书中终止”的解决方法
查看>>
input type=“button“与input type=“submit“的区别
查看>>
解决Github代码下载慢问题!
查看>>
1.idea中Maven创建项目及2.对idea中生命周期的理解3.pom文件夹下groupId、artifactId含义
查看>>
LeetCode-栈|双指针-42. 接雨水
查看>>
stdin,stdout,stderr详解
查看>>
Linux文件和设备编程
查看>>
文件描述符
查看>>
终端驱动程序:几个简单例子
查看>>
登录linux密码验证很慢的解决办法
查看>>
fcntl函数总结
查看>>
HTML条件注释
查看>>