es请求方式调用
Es基础
关系:
ElasticSearch-> mysql
index (索引)-> 数据库
Documents(文档) -> row(行)
Fileds(字段)-> column
正排索引 id 内容,类似表格
倒排索引 :keywords : ids
Postman访问实例
创建索引:创建库
ip/索引名
请求路径:PUT http://127.0.0.1:9200/shopping
请求体:none
成功:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "shopping"
}
查询当前存在索引:
ip/_cat/indices?v=
请求路径:GET http://127.0.0.1:9200/_cat/indices?v=
请求体:none
成功:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .geoip_databases 5vZtZiLXTw-ZnE-gxFK4RA 1 0 33 35 34.1mb 34.1mb
yellow open user1 XvuPXH4GR3qu9kYgI1vMTg 1 1 0 0 226b 226b
yellow open product OuJtZ2GNQjaANql9jHIhdw 1 1 0 0 226b 226b
yellow open user 84VHenNTTtaJyKUQasAZXA 1 1 3 0 4.8kb 4.8kb
yellow open shopping vqraISHNSFioVa4h58y_4w 1 1 10 6 28kb 28kb
创建文档:添加行数据
ip/索引名/_doc
请求路径: POST http://127.0.0.1:9200/shopping/_doc
请求体:
{
"name": "小米",
"price": 1999,
"url": "htp12344"
}
成功:
{
"_index": "shopping",
"_type": "_doc",
"_id": "0i0_WI8Bs7gKHbbSH-sS",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 20,
"_primary_term": 7
}
指定id创建文档:
ip/索引名/_doc/id
请求路径:POST http://127.0.0.1:9200/shopping/_doc/1006
请求体:
{
"name": "魅族21",
"price": 2999,
"url": "htp12344"
}
成功:
{
"_index": "shopping",
"_type": "_doc",
"_id": "1006",
"_version": 3,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 21,
"_primary_term": 7
}
查询单挑索引:查询单条数据
ip/索引/_doc/id
请求路径: GET http://127.0.0.1:9200/shopping/_doc/1001
请求体:none
成功:
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_version": 6,
"_seq_no": 7,
"_primary_term": 1,
"found": true,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
}
查询文档列表:列表查询数据
ip/索引/_search
请求路径: GET http://127.0.0.1:9200/shopping/_search
请求体:none
成功:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "F2NHrY4BJgxAo-jxuDZv",
"_score": 1,
"_source": {
"name": "小米",
"price": 1999,
"url": "htp12344"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_score": 1,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1004",
"_score": 1,
"_source": {
"name": "华为",
"price": 9999,
"url": "htp123"
}
}
]
}
}
条件查询:拆词查询
请求路径: GET http://127.0.0.1:9200/shopping/_search
{
"query": {
"match": { //拆词单个查询
"name": "华"
}
}
}
成功:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.3340157,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "1005",
"_score": 1.3340157,
"_source": {
"name": "华为",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1004",
"_score": 1.3340157,
"_source": {
"name": "华为",
"price": 9999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_score": 1.1120224,
"_source": {
"name": "华为1",
"price": 9999,
"url": "htp123"
}
}
]
}
}
全词匹配查询高亮查询:
请求路径: GET http://127.0.0.1:9200/shopping/_search
请求体:
{
"query": {
"match_phrase": { //全词匹配查询
"name": "华为1"
}
},
"highlight": { //高亮显示这个字段
"fields": {
"name": {}
}
}
}
成功:
{
"took": 58,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 4.0541162,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_score": 4.0541162,
"_source": {
"name": "华为1",
"price": 9999,
"url": "htp123"
},
"highlight": {
"name": [
"<em>华</em><em>为</em><em>1</em>"
]
}
}
]
}
}
多条件范围查询:
请求路径: GET http://127.0.0.1:9200/shopping/_search
请求体:
{
"query": {
"bool": {
"must": [ //should表示或,must表示并
{
"match": {
"name": "小米"
}
},
{
"match": {
"price": 3999
}
}
],
"filter": {
"range": {
"price": {
"lt": 5000
}
}
}
}
}
}
成功:
{
"took": 18,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 2.4093566,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "jFvSmY4BzKCXziUqmd-Q",
"_score": 2.4093566,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "jVvYmY4BzKCXziUqX9-H",
"_score": 2.4093566,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
}
]
}
}
聚合查询:
请求路径: GET http://127.0.0.1:9200/shopping/_search
请求体:
{
"aggs": {
"price_group": { //随意取名
"terms": { //分组
"field": "price" //分组字段
}
}
}
}
{
"took": 38,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "F2NHrY4BJgxAo-jxuDZv",
"_score": 1,
"_source": {
"name": "小米",
"price": 1999,
"url": "htp12344"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "jFvSmY4BzKCXziUqmd-Q",
"_score": 1,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "jVvYmY4BzKCXziUqX9-H",
"_score": 1,
"_source": {
"name": "小米",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "0i0_WI8Bs7gKHbbSH-sS",
"_score": 1,
"_source": {
"name": "魅族",
"price": 1999,
"url": "htp12344"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1005",
"_score": 1,
"_source": {
"name": "华为",
"price": 3999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1002",
"_score": 1,
"_source": {
"name": "小米",
"price": 1999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1003",
"_score": 1,
"_source": {
"name": "小米",
"price": 999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1004",
"_score": 1,
"_source": {
"name": "华为",
"price": 9999,
"url": "htp123"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1006",
"_score": 1,
"_source": {
"name": "魅族21",
"price": 2999,
"url": "htp12344"
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_score": 1,
"_source": {
"name": "华为1",
"price": 9999,
"url": "htp123"
}
}
]
},
"aggregations": {
"price_group": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1999,
"doc_count": 3
},
{
"key": 3999,
"doc_count": 3
},
{
"key": 9999,
"doc_count": 2
},
{
"key": 999,
"doc_count": 1
},
{
"key": 2999,
"doc_count": 1
}
]
}
}
}
文档修改:修改行数据
ip/索引/_doc/id
请求路径: PUT http://127.0.0.1:9200/shopping/_doc/1001
请求体:
{
"name": "小米",
"price": 9999,
"url": "htp123"
}
成功:
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_version": 7,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 22,
"_primary_term": 7
}
局部修改文档(某列)
ip/索引/_update/id
请求路径:PUT http://127.0.0.1:9200/shopping/_update/1001
请求体:
{
"doc": {
"name": "华为1"
}
}
成功:
{
"_index": "shopping",
"_type": "_doc",
"_id": "1001",
"_version": 8,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 23,
"_primary_term": 7
}
删除文档:
请求路径:DELETE http://127.0.0.1:9200/shopping/_doc/1001
请求体:none
es请求方式调用的更多相关文章
- 如何让window.open()以post请求方式调用(巧妙解法)
问题由来: 在公司遇到一个线上bug,如下 var url = 'http://106.75.31.215:8012/onlinePreview?url=' + encodeURIComponent( ...
- Feign服务调用请求方式及参数总结
前言 最近做微服务架构的项目,在用feign来进行服务间的调用.在互调的过程中,难免出现问题,根据错误总结了一下,主要是请求方式的错误和接参数的错误造成的.在此进行一下总结记录.以下通过分为三种情况说 ...
- 百度网盘上下载文件,调用api接口的请求方式和参数
REST api 功能:下载单个文件. Download接口支持HTTP协议标准range定义,通过指定range的取值可以实现断点下载功能. 例如: 如果在request消息中指定“Range: b ...
- C# 通过模拟http请求来调用soap、wsdl
C#调用webservice的方法很多,我说的这种通过http请求模拟来调用的方式是为了解决C#调用java的远程API出现各种不兼容问题. 由于远程API不在我们的控制下,我们只能修改本地的调用代码 ...
- WCF的Restful和TCP方式调用性能比较
1. 实验背景关于WCF提供分布式访问服务,最常用的两种方式Restful方式和Tcp方式,在本地测试了一把.结果显示,还是Rest方式,在压力测试下,性能最佳.而且处于跨平台的考虑,和自动化测试方便 ...
- HttpClient Get/Post方式调用Http接口
本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...
- jQuery中ajax的4种常用请求方式
jQuery中ajax的4种常用请求方式: 1.$.ajax()返回其创建的 XMLHttpRequest 对象. $.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数 ...
- C#以post方式调用struts rest-plugin service的问题
struts2: 玩转 rest-plugin一文中,学习了用struts2开发restful service的方法,发现用c#以post方式调用时各种报错,但java.ajax,包括firefox ...
- WEB API 中HTTP的get、post、put,delete 请求方式
一.WEB API 中HTTP 请求方式的四个主要方法 (GET, PUT, POST, DELETE), 按照下列方式映射为 CURD 操作: 1.POST 用于新建资源,服务端在指定的URI 上创 ...
- jQuery中的Ajax几种请求方式
1. load( url, [data], [callback] ) :载入远程 HTML 文件代码并插入至 DOM 中. url (String) : 请求的HTML页的URL地址. data (M ...
随机推荐
- 5 JavaScript变量提升
5 变量提升 看以下代码, 或多或少会有些问题的. function fn(){ console.log(name); var name = '大马猴'; } fn() 发现问题了么. 这么写代码, ...
- #树状数组,哈希#洛谷 6687 论如何玩转 Excel 表格
题目 分析 首先一列的数不会发生变化,只是交换列, 并且交换列的时候奇数列变成偶数列取反, 偶数列变成奇数列取反,考虑直接将偶数列全部取反, 那只需要交换列就可以了,奇数列交换到偶数列会取反, 奇数列 ...
- 带你玩转OpenHarmony AI-基于海思NNIE的AI能力自定义
简介 相信大家从玩转OpenAtom OpenHarmony(简称"OpenHarmony")AI系列专题的其他文章中,已经拓展了OpenHarmony AI在智慧出行.智慧办公等 ...
- 掌握 C++ 编译过程:面试中常见问题解析
C++是一种高级编程语言,但是计算机并不能直接理解它.因此,需要将C++代码翻译成计算机可以理解的机器语言.这个过程就是编译过程,是C++程序从源代码到可执行文件的转换过程,包括预处理.编译.汇编和链 ...
- Windows wsl2安装Ubuntu
wsl(Windows Subsystem for Linux)即适用于Windows的Linux子系统,是一个实现在Windows 10 / 11上运行原生Linux的技术. wsl2 为其迭代版本 ...
- HarmonyOS Codelab 优秀样例——购物应用,体验一次开发多端部署魅力
一. 样例介绍 本篇Codelab基于自适应布局和响应式布局,实现购物应用在手机.折叠屏.平板不同屏幕尺寸设备上按不同设计显示.通过三层工程结构组织代码,实现一次开发,多端部署 . 手机运行效果如图所 ...
- Stage模型深入解读
原文链接:https://mp.weixin.qq.com/s/4Mb5BMw1IgKvqE0Ff9Ts-w,点击链接查看更多技术内容: HarmonyOS 3.1版本(API 9)推出了全新应 ...
- k8s集群安装(kubeadm方式)
一.准备三台虚拟机,系统CentOS7.9: 192.168.1.221 master1 192.168.1.189 node1 192.168.1.60 node2 二..对三台虚拟机初始化 1 ...
- springboot多模块项目启动经历
springboot多模块使用 @ 目录 springboot多模块使用 前言 大佬把项目权限给我了,我就先下下来看看学习一下 一.识别 二.maven配置 1.安装maven 三.加载刷新 总结 前 ...
- 赋予企业更多可能,云数据库SQL Server 2019版这几大亮点别错过
直播预告 2020年3月26日 15:00-16:30 邀您一同见证 云数据库SQL Server 2019版重磅发布 全面提升性价比及数据库能力 点我观看 RDS SQL Server 2019不仅 ...