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. 实现一个简单的echarts词云图PythonFlask

    cloud.html 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta char ...

  2. #贪心#CF1054D Changing Array

    题目 给定 \(n\) 个 \(k\) 位二进制数,\(n\leq 2*10^5,k\leq 30\) 可以选择若干数将其所有二进制位取反, 最多可以有多少个区间的异或和不为 0 分析 考虑将区间异或 ...

  3. 精彩预告 | OpenHarmony即将亮相MTSC 2023

    MTSC 2023 第 12 届中国互联网测试开发大会(深圳站)即将于 2023 年 11 月 25 日,在深圳登喜路国际大酒店举办,大会将以"1 个主会场+4 个平行分会场"的形 ...

  4. 10.1K star !牛逼了!开源技术速查表,推荐人手一份!

    1.前言 在当今信息爆炸的时代,知识的获取.整理和应用显得尤为重要.随着个人职业发展和学习需求的不断提升,搭建一个个人知识库已成为提升竞争力的关键一环.个人知识库不仅是一个信息的存储库,更是一个思维的 ...

  5. HH的项链—树状数组

    题目描述 HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义. HH不断地收集新的贝壳,因此他的项链变得越来越长.有一天 ...

  6. linux 性能自我学习 ———— 不可中断进程和僵尸进程 [四]

    前言 简单介绍一下不可中断进程和僵尸进程. 正文 先来看下进程的状态: 那么这一列的状态是什么呢? R 是Running 或 Runnable 的缩写, 表示进程在cpu 的就绪队列中,正在运行或者正 ...

  7. python实现:有一个列表为num_list,找到一个具有最大和的连续子列表,返回其最大和。

    # 有一个列表为num_list,找到一个具有最大和的连续子列表,返回其最大和.# 示例:# 输入: [-3,1,-1,6,-1,2,4,-5,4]# 输出: 11# 解释: 连续子数组 [6,-1, ...

  8. lattice的ip不显示,如何解决

    最近ip服务器可能会遇到问题,建议客户把更新检查关掉.我们有对应的IP下载链接.   diamond在     https://www.latticesemi.com/ispupdate/ipexpr ...

  9. 4款值得推荐的AI辅助编程工具(支持C#语言)

    前言 在这个AI迅速发展的阶段,涌现出了一大批好用的AI辅助编程工具.AI辅助编程工具能够提高开发效率.改善代码质量.降低bug率,是现代软件开发过程中的重要助手.今天大姚给大家分享4款AI辅助编程工 ...

  10. nuxt按需引入组件库(却加载所有图标问题),nuxt性能优化。

    做一个官网,nuxt按需引入了antd_vue组件库,但是项目打包时,图标却又500K+,经过排查,发现icon和其他组件环环相扣的.如下:(我引入了这个翻页的组件,里面包含了两个翻页的图标) 但是它 ...