当前位置: 首页 > 编程日记 > 正文

Elasticsearch6.1.3 for CRUD

为什么80%的码农都做不了架构师?>>>   hot3.png

一、创建文档

[root@ AOS2 @AutoTest01:/root]#curl -X PUT '9.1.6.140:9200/students/class1/1?pretty' -d '
> {
>       "first_name": "changwei",
>    "last_name": "kang",
>       "gender": "male",
>    "age": 28,
>    "courses": "IT services"
> }'
{"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported","status" : 406
}
创建文档报错,es6版本要求更加严格需要加上-H 'Content-Type: application/json'[root@ AOS2 @AutoTest01:/root]#curl -X PUT '9.1.6.140:9200/students/class1/1?pretty' -H 'Content-Type: application/json' -d '
{"first_name": "changwei","last_name": "kang","gender": "male","age": 28,"courses": "IT services"
}'
{"_index" : "students","_type" : "class1","_id" : "1","_version" : 2,"result" : "updated","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 1,"_primary_term" : 1
}

二、获取文档

[root@ AOS2 @AutoTest01:/root]#curl -XGET 'localhost:9200/students/class1/1?pretty'
{"_index" : "students","_type" : "class1","_id" : "1","_version" : 3,"found" : true,"_source" : {"first_name" : "changweiA","last_name" : "kangA","gender" : "male","age" : 28,"courses" : "IT services"}
}创建[root@ AOS2 @AutoTest01:/root]#curl -X PUT '9.1.6.140:9200/students/class1/2?pretty' -H 'Content-Type: application/json' -d '
{"first_name": "changweiAaa","last_name": "kangAaa","gender": "maleaa","age": 28,"courses": "IT services aa"
}'
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 2,"result" : "updated","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 1,"_primary_term" : 1
}
获取
[root@ AOS2 @AutoTest01:/root]#curl -XGET 'localhost:9200/students/class1/2?pretty'
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 2,"found" : true,"_source" : {"first_name" : "changweiAaa","last_name" : "kangAaa","gender" : "maleaa","age" : 28,"courses" : "IT services aa"}
}

三、更新文档

[root@ AOS2 @AutoTest01:/root]#curl -XPOST '9.1.6.140:9200/students/class1/2/_update?' -d '
> {
>    "doc": {"courses": "chushichushichushi"}
> }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}[
报错忘了加个参数
修改
[root@ AOS2 @AutoTest01:/root]#curl -XPOST '9.1.6.140:9200/students/class1/2/_update?pretty' -H 'Content-Type: application/json' -d '{                                          "doc": {"courses": "chushichushichushiaaaaaaaaa"}
}'
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 4,"result" : "updated","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 3,"_primary_term" : 1
}
查看
[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/students/class1/2?pretty'                                    
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 4,"found" : true,"_source" : {"first_name" : "changweiAaa","last_name" : "kangAaa","gender" : "maleaa","age" : 28,"courses" : "chushichushichushiaaaaaaaaa"}
}
修改成功

四、删除文档

删除数据
[root@ AOS2 @AutoTest01:/root]# curl -XDELETE '9.1.6.140:9200/students/class1/1?pretty'
{"_index" : "students","_type" : "class1","_id" : "1","_version" : 4,"result" : "deleted","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 3,"_primary_term" : 1
}
[root@ AOS2 @AutoTest01:/root]# curl -XDELETE '9.1.6.140:9200/students/class1/2?pretty'
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 5,"result" : "deleted","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 4,"_primary_term" : 1
}
再次查看
[root@ AOS2 @AutoTest01:/root]# curl -XGET '9.1.6.140:9200/students/class1/2?pretty'
{"_index" : "students","_type" : "class1","_id" : "2","found" : false
}查看索引
[root@ AOS2 @AutoTest01:/root]#curl -XGET 'localhost:9200/_cat/indices?v'
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   students H0z_SQQ2Q_-cXWKmAECBjg   5   1          2            0     23.6kb         11.8kb
删除索引
[root@ AOS2 @AutoTest01:/root]# curl -XDELETE '9.1.6.140:9200/students?pretty'
{"acknowledged" : true
}
查看索引
[root@ AOS2 @AutoTest01:/root]#curl -XGET 'localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

五、简单查询

1、request API 查询

先创建数据
[root@ AOS2 @AutoTest01:/root]#curl -X PUT '9.1.6.140:9200/students/class1/1?pretty' -H 'Content-Type: application/json' -d '
{"first_name": "kang wang","last_name": "changweikang","gender": "male","age": 25,"courses": "IT Services Linux"
}'
{"_index" : "students","_type" : "class1","_id" : "1","_version" : 2,"result" : "updated","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 1,"_primary_term" : 1
}
[root@ AOS2 @AutoTest01:/root]#curl -X PUT '9.1.6.140:9200/students/class1/2?pretty' -H 'Content-Type: application/json' -d '
{"first_name": "kang","last_name": "changwei","gender": "male","age": 25,"courses": "IT Services"
}'
{"_index" : "students","_type" : "class1","_id" : "2","_version" : 1,"result" : "created","_shards" : {"total" : 2,"successful" : 2,"failed" : 0},"_seq_no" : 0,"_primary_term" : 1
}
查询所有文档方法_serach
[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/students/_search?pretty'
{"took" : 22,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},   上面为查询执行的相关信息下面为命中文档的相关信息"hits" : {"total" : 2,"max_score" : 1.0,"hits" : [{"_index" : "students","_type" : "class1","_id" : "2","_score" : 1.0,"_source" : {"first_name" : "kang","last_name" : "changwei","gender" : "male","age" : 25,"courses" : "IT Services"}},{"_index" : "students","_type" : "class1","_id" : "1","_score" : 1.0,"_source" : {"first_name" : "kang wang","last_name" : "changweikang","gender" : "male","age" : 25,"courses" : "IT Services Linux"}}]}
}查询kang字符串的数据
[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/_search?q='kang''
{"took":132,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":2,"max_score":0.2876821,"hits":[{"_index":"students","_type":"class1","_id":"2","_score":0.2876821,"_source":
{"first_name": "kang","last_name": "changwei","gender": "male","age": 25,"courses": "IT Services"
}},{"_index":"students","_type":"class1","_id":"1","_score":0.2876821,"_source":
{"first_name": "kang wang","last_name": "changweikang","gender": "male","age": 25,"courses": "IT Services Linux"
}}]}}[root@ AOS2 @AutoTest01:/root]#更直观的json格式
[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/_search?q='kang'&pretty'
{"took" : 8,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 2,"max_score" : 0.2876821,"hits" : [{"_index" : "students","_type" : "class1","_id" : "2","_score" : 0.2876821,"_source" : {"first_name" : "kang","last_name" : "changwei","gender" : "male","age" : 25,"courses" : "IT Services"}},{"_index" : "students","_type" : "class1","_id" : "1","_score" : 0.2876821,"_source" : {"first_name" : "kang wang","last_name" : "changweikang","gender" : "male","age" : 25,"courses" : "IT Services Linux"}}]}
}多索引、多类型查询:/_search:所有索引;/INDEX_NAME/_search:单索引;/INDEX1,INDEX2/_search:多索引;/s*,t*/_search:/students/class1/_search:单类型搜索/students/class1,class2/_search:多类型搜索对每一个文档,会取得其所有域的所有值,生成一个名为“_all”的域;执行查询时,如果在query_string未指定查询的域,则在_all域上执行查询操作;GET /_search?q='Kang'GET /_search?q='IT20%Linux'GET /_search?q=courses:'IT%20Linux'GET /_search?q=courses:'Linux'

搜索制定域的字段

[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/_search?q=courses:Linux&pretty'
{"took" : 4,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 1,"max_score" : 0.2876821,"hits" : [{"_index" : "students","_type" : "class1","_id" : "1","_score" : 0.2876821,"_source" : {"first_name" : "kang wang","last_name" : "changweikang","gender" : "male","age" : 25,"courses" : "IT Services Linux"}}]}
}

2、request body查询

此种查询可以编写更为复杂的查询

[root@ AOS2 @AutoTest01:/root]#curl -XGET '9.1.6.140:9200/students/_search?pretty' -H 'Content-Type: application/json'  -d '
{"query":{ "match_all": {}  }
}'
{"took" : 9,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 2,"max_score" : 1.0,"hits" : [{"_index" : "students","_type" : "class1","_id" : "2","_score" : 1.0,"_source" : {"first_name" : "kang","last_name" : "changwei","gender" : "male","age" : 25,"courses" : "IT Services"}},{"_index" : "students","_type" : "class1","_id" : "1","_score" : 1.0,"_source" : {"first_name" : "kang wang","last_name" : "changweikang","gender" : "male","age" : 25,"courses" : "IT Services Linux"}}]}
}

转载于:https://my.oschina.net/kcw/blog/1619827

相关文章:

指纹锁就安全了?防火防盗还得防AI

整理 | 一一 出品 | AI科技大本营(ID:rgznai100) 如何挑战百万年薪的人工智能 https://edu.csdn.net/topic/ai30?utm_sourcecsdn_bw 近日,你应该看到了社交媒体上对于网站 ThisPersonDoesNotExist.com,生成无数不存在人脸的铺天…

迪杰斯特拉算法(C语言实现)

迪杰斯特拉算法(C语言实现) 如上图,求以a为源点到个顶点的最短路劲。 #include "stdio.h"#include "stdlib.h"//用一个最大数表示顶点之间不相关#define MAX 999//设置顶点个数#define MAX_VERTEX_NUM 7//表示顶点之间不…

小米半年来最大调整:成立技术委员会,雷军称技术事关生死存亡

整理 | 琥珀出品 | AI科技大本营(ID:rgznai100)昨晚,小米集团组织部下发正式文件,宣布了最新一轮组织架构调整,任命了崔宝秋为集团副总裁,集团技术委员会主席,并且在核心管理岗位上共任命了 14 …

【驱动】在内核源码中添加驱动程序

以wifi驱动(RTL8188EUS驱动)为例 添加源码 将源码rtl8188EUS添加到drivers/net/wireless/rtl818x/目录下 添加Kconfig 在drivers/net/wireless/rtl818x/rtl8188EUS添加Kconfig,内容如下: config RTL8188EUtristate "Realtek 8188E USB WiFi&qu…

怎么让wordpress用sqlite3 搭建轻量级博客系统

wordpress 默认是用mysql作为数据库支持,这个对个人站长来说还是有点麻烦了些。特别是如果以后网站备份迁移就有点事多了。 之前用django开发自己的博客感觉其实用sqlite3作为数据库插好,就是一个文件而已。备份网站,直接打包整个目录即可方便…

IBM蓝色基因/Q将采用NAND闪存存储

IBM将在计划中的高性能“怪兽”——蓝色基因/Q中采用NAND闪存存储。 这是一款采用水冷方式的高性能计算系统,IBM在近日的SC10大会上展示了其原型机的组件。 蓝色基因/Q将采用的闪存是来自SMART的XceedIOPS MLC NAND产品,它使用34nm制程工艺&…

全球超2万名开发者调研:Python 3渗透率至84%

编辑 | suiling 出品 | Python大本营(ID:pythonnews) 60s测试:你是否适合转型人工智能? https://edu.csdn.net/topic/ai30?utm_sourcecxrs_bw 在2018年秋季,Python软件基金会与JetBrains发起了年度Python…

【Qt】QWidget对样式表设置边框无效的解决方法

1、现象 在对QWidget使用样式表时无效 QWidget#MyWgt{border:1px solid gray; }2、原因 原因是QWidget只支持background、background-clip和background-origin属性。 3、解决方法 3.1 使用QFrame代替QWidget,QFrame继承自QWidget,并且带有框架属性 …

break continue

break 终止整个循环体,执行循环后的代码; continue 终止单次的循环,整个循环体还是会继续执行转载于:https://www.cnblogs.com/RonnieQin/p/8430783.html

CSSA email list

UCSD: cssamailman.ucsd.eduUChicago: cssalists.uchicago.edu 转载于:https://www.cnblogs.com/stoneresearch/archive/2010/11/30/4336484.html

LVS原理详解(3种工作方式8种调度算法)--老男孩

一、LVS原理详解(4种工作方式8种调度算法)集群简介集群就是一组独立的计算机,协同工作,对外提供服务。对客户端来说像是一台服务器提供服务。LVS在企业架构中的位置:以上的架构只是众多企业里面的一种而已。绿色的线就…

【Qt】QMainWindow最大化按钮是灰色(不能最大化)的解决方法

解决方法 设置最大尺寸为16777215,并且使能Qt::WindowMaximizeButtonHint(默认就是使能的,不执行也可以) const QSize MAIN_SIZE_MAX QSize(16777215, 16777215); this->setMaximumSize(MAIN_SIZE_MAX); this->setWindow…

“AI明星”地平线B轮融资6亿美元!

整理 | 一一 出品 | AI科技大本营(ID:rgznai100) 60s测试:你是否适合转型人工智能? https://edu.csdn.net/topic/ai30?utm_sourcecxrs_bw 2 月 27 日,人工智能芯片技术的 AI 创业企业地平线(Horizon Robotics)宣布&a…

C++深拷贝与浅拷贝

浅拷贝就是成员数据之间的一一赋值:把值赋给一一赋给要拷贝的值。但是可能会有这样的情况:对象还包含资源,这里的资源可以值堆资源,或者一个文件。。当 值拷贝的时候,两个对象就有用共同的资源,同时对资源可…

【OpenCV】使用过的函数汇总

1、类 Mat:矩阵matrix,opencv2中主要用来封装图片数据 InputArray:输入参数 ,约等于Mat OutputArray:输出参数,约等于Mat Rect:表示矩形 2、函数 imread();//从文件中读取图片到Mat中 imwrit…

春招来袭!程序员如何拿下硅谷顶级公司200万年薪?

还记得那个在去年,用 6 天时间参加了 LinkedIn、Yelp、Apple、亚马逊、Facebook 和 Google 的面试,并拿下了 6 份 Offer 的“别人家的程序员”吗?之后,他又在这几份工作中进行了选择,一步步谈下了 30 万美元&#xff0…

wake_lock_timeout的使用方法【转】

本文转载自:http://blog.csdn.net/liuxd3000/article/details/44224849 今天有用到用ec43_GPIO的中断来唤醒系统,将系统从深度休眠中唤醒并保证系统wakup 一段时间用过了,方法如下,有同样使用的童鞋可以参考一下!1. …

函数05 - 零基础入门学习C语言36

第七章:函数05 让编程改变世界 Change the world by program 函数的嵌套调用 嵌套定义就是在定义一个函数时,其函数体内又包含另一个函数的完整定义。 然而,C语言不能嵌套定义函数,但可以嵌套调用函数,…

【linux】可执行程序执行时报错-sh: ./mxc_v4l2_tvin.out: No such file or directory的解决方法

问题 在imx6开发板上执行 ./mxc_v4l2_tvin.out时报错: -sh: ./mxc_v4l2_tvin.out: No such file or directory 原因查找 1、路径问题:确定在当前目录下有该程序,没问题; 2、使用ls -l查看可以执行权限,没问题&…

展望2018:WebRTC大规模商用元年

历经6年长跑,WebRTC终于在去年迎来了1.0标准(candidate recommendation)的发布,而它也将成为2018年视频通信商业应用场景爆发的主要技术推动力。一站式WebRTC通信技术提供商Zealcomm公司创始人、CEO冯昶对WebRTC在国内外发展历程、…

暴雪游戏遭遇AI“实力”坑队友:四处游走,还不参与战斗

作者 | 琥珀 出品 | AI科技大本营(ID: rgznai100) 60s测试:你是否适合转型人工智能? https://edu.csdn.net/topic/ai30?utm_sourcecxrs_bw “打游戏 AI 将完胜人类!?” 抱歉,这个 Flag 还是不…

linux/nginx 安全增强

这有一篇很好的文章. 评论中有好的补充 http://www.cyberciti.biz/tips/linux-unix-bsd-nginx-webserver-security.html转载于:https://www.cnblogs.com/pengxl/archive/2010/12/08/1900175.html

十年程序员的告诫:千万不要重写代码!

对重写代码说不。 作者 | Roman Luzgin 译者 | 苏本如 责编 | 屠敏 出品 | CSDN(ID:CSDNNews) 以下为译文: 重写代码消耗了12个月! 我们从头开始重写代码浪费的时间。 你能想象在软件行业,12个月的时…

RabbitMQ 实战(四)消费者 ack 以及 生产者 confirms

2019独角兽企业重金招聘Python工程师标准>>> 这篇文章主要讲 RabbitMQ 中 消费者 ack 以及 生产者 confirms。 如上图,生产者把消息发送到 RabbitMQ,然后 RabbitMQ 再把消息投递到消费者。 生产者和 RabbitMQ,以及 RabbitMQ 和消费…

【imx6】/dev中fb和video的对应关系

imx6q关于fb和video的设备信息 设备节点 rootmyzr:/unit_tests# ls /dev/fb* -l lrwxrwxrwx 1 root root 3 Jan 1 1970 /dev/fb -> fb0 crw-rw---- 1 root video 29, 0 Jan 1 1970 /dev/fb0 crw-rw---- 1 root video 29, 1 Jan 1 1970 /dev/fb1 crw-rw---- 1 r…

flash绘图API:恋上你的CD

早上,我无意间碰撞到一个女孩,那时候,她匆匆忙地走了。从她的口袋里面掉下了一本陈旧的书,在哪里我看到她藏在书中的那封陈旧的信和cd。我好奇打开它,一边听着她那张cd,一边看她的写的信,忽然间…

【Ubuntu】ubuntu工具 记录shell终端的内容到文件中:script

###用法 $ script -h Usage: script [options] [file] Options: -a, --append append the output -c, --command run command rather than interactive shell -r, --return return exit code of the child process -f, --flush run flush after each write –force use outpu…

弃Java、Swift于不顾,为何选Python?

作者 | JACE HARR译者 | 姜松浩转载自 CSDN(ID:CSDNNews)以下为译文:刚入行的程序员总是询问他们应该从哪种语言开始,我告诉他们,他们应该首先学习 Python。以下是使用 Python 开始自学编程去探险的一些原因…

iOS事件处理,看我就够了~

该文章属于<简书 — 刘小壮>原创&#xff0c;转载请注明&#xff1a; <简书 — 刘小壮> https://www.jianshu.com/p/b0884faae603 好久没写博客了&#xff0c;前后算起来刚好有一年了。这期间博客也不是一直没变化&#xff0c;细心的同学应该能发现&#xff0c;我一…

ISO9000机房管理办法

1 总则<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" />1.1制定目的(1) 规范公司机房管理以及网管相关工作。1.2适用范围公司网络机房以及资讯组人员。1.3权责单位(1) 资讯组负责本办法制定、修改、废止之起草工作。(2) 总…