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请求方式调用的更多相关文章

  1. 如何让window.open()以post请求方式调用(巧妙解法)

    问题由来: 在公司遇到一个线上bug,如下 var url = 'http://106.75.31.215:8012/onlinePreview?url=' + encodeURIComponent( ...

  2. Feign服务调用请求方式及参数总结

    前言 最近做微服务架构的项目,在用feign来进行服务间的调用.在互调的过程中,难免出现问题,根据错误总结了一下,主要是请求方式的错误和接参数的错误造成的.在此进行一下总结记录.以下通过分为三种情况说 ...

  3. 百度网盘上下载文件,调用api接口的请求方式和参数

    REST api 功能:下载单个文件. Download接口支持HTTP协议标准range定义,通过指定range的取值可以实现断点下载功能. 例如: 如果在request消息中指定“Range: b ...

  4. C# 通过模拟http请求来调用soap、wsdl

    C#调用webservice的方法很多,我说的这种通过http请求模拟来调用的方式是为了解决C#调用java的远程API出现各种不兼容问题. 由于远程API不在我们的控制下,我们只能修改本地的调用代码 ...

  5. WCF的Restful和TCP方式调用性能比较

    1. 实验背景关于WCF提供分布式访问服务,最常用的两种方式Restful方式和Tcp方式,在本地测试了一把.结果显示,还是Rest方式,在压力测试下,性能最佳.而且处于跨平台的考虑,和自动化测试方便 ...

  6. HttpClient Get/Post方式调用Http接口

    本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...

  7. jQuery中ajax的4种常用请求方式

    jQuery中ajax的4种常用请求方式: 1.$.ajax()返回其创建的 XMLHttpRequest 对象. $.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数 ...

  8. C#以post方式调用struts rest-plugin service的问题

    struts2: 玩转 rest-plugin一文中,学习了用struts2开发restful service的方法,发现用c#以post方式调用时各种报错,但java.ajax,包括firefox ...

  9. WEB API 中HTTP的get、post、put,delete 请求方式

    一.WEB API 中HTTP 请求方式的四个主要方法 (GET, PUT, POST, DELETE), 按照下列方式映射为 CURD 操作: 1.POST 用于新建资源,服务端在指定的URI 上创 ...

  10. jQuery中的Ajax几种请求方式

    1. load( url, [data], [callback] ) :载入远程 HTML 文件代码并插入至 DOM 中. url (String) : 请求的HTML页的URL地址. data (M ...

随机推荐

  1. 【已解决】java.text.ParseException: Unparseable date

    今天在工作的时候遇到一个问题,我的一个字段queryDate保存不了,总是null值: java.text.ParseException: Unparseable date 报错的原因是日期格式转换错 ...

  2. #平衡树#洛谷 2611 [ZJOI2012]小蓝的好友

    题目 在 \(R\times C\) 的矩形中,问有多少个子矩形使得存在一个给定点在其中, 保证点随机,\(R,C\leq 4\times 10^4,n\leq 10^5\) 分析 考虑容斥,用总方案 ...

  3. 对OpenHarmony中LiteOS的内核分析——超时原理和应用

    前言 在软件世界里面,超时是一个非常重要的概念.比如 ● 当前线程暂时休眠1秒钟,休眠结束后继续执行 ● 每5秒钟采集一下CPU利用率 ● 数据发送失败,2秒钟以后再试一试 ● 等待某种数据,但最多等 ...

  4. 数据库SQL(MSSQLSERVER)服务启动错误代码3414

    昨天永和客户联系我,说他们的前台系统报错了,给我发了报错的图片.看到错误的第一眼就知道是数据库出问题了,连不上sql Server. 虽然知道是数据库出问题了,但是刚开始的时候没有打开SQL Serv ...

  5. vue3探索——组件通信之v-model父子组件数据同步

    背景 再很多场景中,我们可能想在子组件中修改父组件的数据,但事实上,vue不推荐我们这么做,因为数据的修改不容易溯源. Vue2写法 在vue2中,我们使用.sync修饰符+自定义事件'update: ...

  6. Linux systemd 定时任务

    哈喽大家好,我是咸鱼. 说到 Linux 定时任务,大家用得最多的就是 crond 服务,但其实 systemd 也有类似的功能.我们不但可以通过 systemd 来管理服务,还能设置定时任务,那就是 ...

  7. python3中os.renames()和os.rename()区别

    renames源码:def renames(old, new): head, tail = path.split(new) # 作用是分割为两部分,head为路径,tail为文件名: if head ...

  8. 当 mysql-connector-java-5 遇上 MySQL8,终究还是错付了 → 门当户对真的很重要!

    开心一刻 今天,老婆给我发消息 老婆:老公,儿子从隔壁邻居家回来了 老婆:是先打还是先洗? 我:先洗吧,万一打错人了呢 老婆:先洗脸吧,没错就边打边洗 起因 在我们的固有认知中, mysql-conn ...

  9. C#微服务必学清单

    在 C# 领域,有一些不错的微服务书籍和开源框架,对于学习微服务相关知识非常有帮助.以下是一些建议您阅读的微服务书目和开源框架. 微服务书目: 1. <Building Microservice ...

  10. HarmonyOS NEXT应用开发—在Native侧实现进度通知功能

    介绍 本示例通过模拟下载场景介绍如何将Native的进度信息实时同步到ArkTS侧. 效果图预览 使用说明 点击"Start Download"按钮后,Native侧启动子线程模拟 ...