当前位置:网站首页>es-head plugin insert query and conditional query (5)
es-head plugin insert query and conditional query (5)
2022-08-11 03:52:00 【Xianling Pavilion】
es-head插件插入查询以及条件查询
1.es-head插件页面介绍
页面详细介绍
2.es-head查询语句
2.1.查询索引中的全部数据
curl命令交互,采用GET请求
语法格式: curl -XGET es地址:9200/索引名/_search?pretty
[[email protected] ~]# curl -XGET 192.168.81.210:9200/testinfo/_search?pretty
复制代码
es-head插件查询索引中的全部数据
在查询的框中填写http://192.168.81.210:9200/testinfo/,填写es地址和查询的索引
_search表示查询索引中的所有数据,类型选择GET,最后点击提交请求
2.2.查询一条数据
curl交互式查询
语法格式:curl -XGET es地址:prot/索引/类型/id?pretty
[[email protected] ~]# curl -XGET 192.168.81.210:9200/testinfo/user/1?pretty
复制代码
es-head查询
地址:http://192.168.81.210:9200/
查询的数据:testinfo/user/3?pretty
类型:GET
3.es-head插入数据
3.1.插入一条数据
curl交互式插入
curl -XPUT ‘192.168.81.240:9200/testinfo/user/3?pretty’ -H 'COntent-Type:
application/json' -d'
{
"first_name" : "xiao",
"last_name" : "ming",
"age" : 99,
"about" : "I like linux", "interests": [ "sports", "music" ]
}'
复制代码
es-head插入
es地址:http://192.168.81.210:9200/
索引:testinfo/user/3?pretty PUT类型
{
"first_name" : "xiao",
"last_name" : "ming",
"age" : 99,
"about" : "I like linux", "interests": [ "sports", "music" ]
}
复制代码
3.2.查看数据是否插入
点击数据浏览一栏,索引选择testinfo
数据浏览这里以_下划线开头的表示es内置字段,无法进行修改数据
每点击一条数据都会有json格式的显示
4.es-head数据浏览查询数据
查询一个first_name包含jiang且age为99的数据
点击数据浏览,在左侧选好索引库
县级age的三角即可弹出输入框,在里面写好99,在点击first_name三角弹出输入框,在里面写好jiang即可
5.es-head基本查询实现复合查询
5.1.查询age范围70-100之间的数据
第二列表示字段,选择age,第三列选择查询类型,我们选择range,range表示范围,第四列第五列选择范围值
5.2.姓氏包含将且年龄在50-100的数据
在上一个基础之上增加一个first_name的字段
这里可以选择输出为什么类型的格式,有table、json、csv
6.es-head随机主机和id
我们实际生产环境中经常需要把mysql的数据导到es集群中,实现大数据分析,但是由于每个索引库都有一个系统生成的id,显然和mysql中的会冲突,这时我们可以在增加一个id列,填写mysql对应的id号,然后索引库中的系统id可以让其自动生成并设置成主键就能完美解决这个问题了
最终的思路就是:系统生成的id号做成主键让系统随机生产,再增加一列作为id,存放mysql系统之前的id号
6.1.创建一个带有系统id和自己定义id的索引库并写入数据
创建一个linuxbook的索引库,类型为book
写入一个数据,id为1,书名称为nginx,书价格为35元,书的页数为206页,书分类为web的数据
[[email protected] ~]# curl -XPOST '127.0.0.1:9200/linuxbook/book?pretty' -H 'Content-Type: application/json' -d '{
"id": 1,
"book_name": "nginx",
"book_jg": "35¥",
"book_ys": "206",
"book_group": "web"
}'
{
"_index" : "linuxbook",
"_type" : "book",
"_id" : "6MfqqXYB46SAjukOX_Wm",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
复制代码
可以看到新增加了一个索引库
6.2.查看我们写入的数据
点击数据浏览—会看到多了个索引,找到我们的linuxbook索引—查看数据
会看到既有随机生产的_id也有我们新增的id
再次插入了几条数据
也可以根据条件去搜索
7.删除索引库
慎用索引库,要删除索引库建议在浏览器页面删除,会有提示
7.1.命令行删除索引库
我们首先创建一个测试库
[[email protected] ~]# curl -XPOST '127.0.0.1:9200/linuxaaa/book?pretty' -H 'Content-Type: application/json' -d '{
"id": 2,
"book_name": "mysql",
"book_jg": "70¥",
"book_ys": "709",
"book_group": "db"
}'
复制代码
删除索引库
[[email protected] ~]# curl -XDELETE '127.0.0.1:9200/linuxaaa?pretty'
{
"acknowledged" : true
}
复制代码
删除成功
7.2.浏览器删除索引库
先创建一个索引库
[[email protected] ~]# curl -XPOST '127.0.0.1:9200/linuxaaa/book?pretty' -H 'Content-Type: application/json' -d '{
"id": 2,
"book_name": "mysql",
"book_jg": "70¥",
"book_ys": "709",
"book_group": "db"
}'
复制代码
删除索引库
1)点击动作—删除
2)在弹出的框中输入删除
3)删除成功
成功删除
8.用head地址访问
本章操作都是用谷歌的head插件去连接的es服务器,我们用服务器中部署的head访问一次
服务器中安装并启动head
[[email protected] data]# tar xf elasticsearch-head.tar.gz
[[email protected] data]# cd elasticsearch-head
[[email protected] elasticsearch-head]# npm install
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {
"os":"darwin","arch":"any"} (current: {
"os":"linux","arch":"x64"})
up to date in 11.943s
?─────────────────────────────────────────────────────────────────?
│ │
│ New minor version of npm available! 6.9.0 → 6.14.10 │
│ Changelog: https://github.com/npm/cli/releases/tag/v6.14.10 │
│ Run npm install -g npm to update! │
│ │
?─────────────────────────────────────────────────────────────────?
[[email protected] elasticsearch-head]# npm run start &
[1] 87691
[[email protected] elasticsearch-head]#
> elasticsearch-head@0.0.0 start /data/elasticsearch-head
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
[[email protected] elasticsearch-head]#
[[email protected] elasticsearch-head]#
[[email protected] elasticsearch-head]#
[[email protected] elasticsearch-head]# netstat -lnpt | grep 9100
tcp 0 0 0.0.0.0:9100 0.0.0.0:* LISTEN 87702/grunt
复制代码
源码附件已经打包好上传到百度云了,大家自行下载即可~
链接: https://pan.baidu.com/s/14G-bpVthImHD4eosZUNSFA?pwd=yu27
提取码: yu27
百度云链接不稳定,随时可能会失效,大家抓紧保存哈.
如果百度云链接失效了的话,请留言告诉我,我看到后会及时更新~
开源地址
码云地址:
http://github.crmeb.net/u/defu
Github 地址:
http://github.crmeb.net/u/defu
作者:jiangxl
链接:https://juejin.cn/post/7130049525250523173
边栏推荐
- Paper Accuracy - 2017 CVPR "High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis"
- 你不知道的 console.log 替代品
- What kind of programming trading strategy types can be divided into?
- 用户如何克服程序化交易中的情绪问题?
- The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
- 80端口和443端口是什么?有什么区别?
- How to delete statements audit log?
- .NET 服务注册
- Element's BFC attribute
- LeetCode刷题第10天字符串系列之《125回文串验证》
猜你喜欢
STC8H开发(十五): GPIO驱动Ci24R1无线模块
Interchangeable Measurement Techniques - Geometric Errors
[FPGA] day19- binary to decimal (BCD code)
轮转数组问题:如何实现数组“整体逆序,内部有序”?“三步转换法”妙转数组
机器学习中什么是集成学习?
Binary tree related code questions [more complete] C language
机器学习怎么学?机器学习流程
你不知道的 console.log 替代品
没想到MySQL还会问这些...
电力机柜数据监测RTU
随机推荐
这些云自动化测试工具值得拥有
Qnet Weak Network Test Tool Operation Guide
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
DNS分离解析和智能解析
我的 archinstall 使用手册
论文精度 —— 2017 CVPR《High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis》
轮转数组问题:如何实现数组“整体逆序,内部有序”?“三步转换法”妙转数组
Detailed explanation of VIT source code
【ADI低功耗2k代码】基于ADuCM4050的ADXL363、TMP75的加速度、温度检测及串口打印、蜂鸣器播放音乐(孤勇者)
高度塌陷问题的解决办法
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
【FPGA】day22-SPI protocol loopback
一文读懂 高性能可预期数据中心网络
Qnet弱网测试工具操作指南
js 将字符串作为js执行代码使用
Audio codec, using FAAC to implement AAC encoding
构建程序化交易系统需要注意什么问题?
Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes
多商户商城系统功能拆解26讲-平台端分销设置
【C语言】入门