ES mget、bulk、mappings

文章目录

    • 1. mget 批量查询
    • 2. bulk 批量写入
    • 3. 条件删除
    • 4. 条件更新
    • 5. 映射 mappings
    • 6. 自动映射
    • 7. 显式映射

1. mget 批量查询

  • 批量查询
GET _mget
{"docs": [{"_index": "test_index","_id": 1},{"_index": "kibana_sample_data_flights","_id": "frc8U4UBIo5EnYllKV0t"}]
}

输出

{"docs": [{"_index": "test_index","_id": "1","_version": 3,"_seq_no": 11,"_primary_term": 1,"found": true,"_source": {"name": "test_new","value": 100,"alisa": "名称"}},{"_index": "kibana_sample_data_flights","_id": "frc8U4UBIo5EnYllKV0t","_version": 1,"_seq_no": 8373,"_primary_term": 1,"found": true,"_source": {"FlightNum": "5EKI6QP","DestCountry": "CN","OriginWeather": "Rain","OriginCityName": "London","AvgTicketPrice": 1028.3575673252506,"DistanceMiles": 5761.935055291024,"FlightDelay": true,"DestWeather": "Sunny","Dest": "Shanghai Pudong International Airport","FlightDelayType": "Late Aircraft Delay","OriginCountry": "GB","dayOfWeek": 5,"DistanceKilometers": 9272.935609622278,"timestamp": "2023-01-14T19:36:28","DestLocation": {"lat": "31.14340019","lon": "121.8050003"},"DestAirportID": "PVG","Carrier": "JetBeats","Cancelled": false,"FlightTimeMin": 902.3525435444484,"Origin": "London Gatwick Airport","OriginLocation": {"lat": "51.14810181","lon": "-0.190277994"},"DestRegion": "SE-BD","OriginAirportID": "LGW","OriginRegion": "GB-ENG","DestCityName": "Shanghai","FlightTimeHour": 15.03920905907414,"FlightDelayMin": 240}}]
}
  • 同 一个 index 可以简写
GET test_index/_mget
{"docs": [{"_id": 1},{"_id": 2}]
}

or

GET test_index/_mget
{"ids": [1,2]
}

2. bulk 批量写入

写入一条

POST _bulk
{"create":{"_index":"test_index","_id":3}}  # action, create 可以改成 index(替换doc)
{"name":"test_new1","value":[1,2,3]}  # data 这两行不能分在多行

写入多条,注意 create、index 的区别

POST _bulk
{"create":{"_index":"test_index","_id":3}}
{"name":"test_new3","value":[1,2,3]}
{"create":{"_index":"test_index","_id":4}}
{"name":"test_new4","value":4}
{"index":{"_index":"test_index","_id":5}}
{"name":"test_new5","value":5}

or 同一index可简写

POST test_index/_bulk
{"create":{"_id":3}}
{"name":"test_new3","value":[1,2,3]}
{"create":{"_id":4}}
{"name":"test_new4","value":4}
{"index":{"_id":5}}
{"name":"test_new5","value":5}
{"took": 168,"errors": true,"items": [{"create": {"_index": "test_index","_id": "3",  # 已经存在,create 报错"status": 409,"error": {"type": "version_conflict_engine_exception","reason": "[3]: version conflict, document already exists (current version [2])","index_uuid": "ntM1X5SOTxiz8tRVwdHK6g","shard": "0","index": "test_index"}}},{"create": {"_index": "test_index","_id": "4","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"_seq_no": 15,"_primary_term": 1,"status": 201}},{"index": {"_index": "test_index","_id": "5","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"_seq_no": 16,"_primary_term": 1,"status": 201}}]
}

update 更新

POST _bulk
{"update":{"_index":"test_index","_id":3}}
{"doc":{"value":3}}
{"update":{"_index":"test_index","_id":4}}
{"doc":{"name":"test_new44"}}
{"update":{"_index":"test_index","_id":5}}
{"doc":{"name":"test_new55","value":55}}

or 简写

POST test_index/_bulk
{"update":{"_id":3}}
{"doc":{"value":3}}
{"update":{"_id":4}}
{"doc":{"name":"test_new44"}}
{"update":{"_id":5}}
{"doc":{"name":"test_new55","value":55}}

delete 删除

POST _bulk
{"delete": {"_index": "test_index", "_id": 3}}
{"delete": {"_index": "test_index", "_id": 4}}

or

POST test_index/_bulk
{"delete": {"_id": 5}}
{"delete": {"_id": "ZLcgV4UBIo5EnYlljo2Q"}}

3. 条件删除

POST test_index/_delete_by_query
{"query": {"term": {"value": 100}}
}

输出

{"took": 297,"timed_out": false,"total": 1,"deleted": 1,"batches": 1,"version_conflicts": 0,"noops": 0,"retries": {"bulk": 0,"search": 0},"throttled_millis": 0,"requests_per_second": -1,"throttled_until_millis": 0,"failures": []
}

检查 value = 100 的 doc 已被删除

GET test_index/_search

4. 条件更新

POST test_index/_update_by_query
{"query": {"term": {"value": 99}},"script": {"source": "ctx._source['value'] = 199"}
}

更新 query 条件下(value=99)的 doc,将其 value 改为 199

输出

{"took": 307,"timed_out": false,"total": 1,"updated": 1,"deleted": 0,"batches": 1,"version_conflicts": 0,"noops": 0,"retries": {"bulk": 0,"search": 0},"throttled_millis": 0,"requests_per_second": -1,"throttled_until_millis": 0,"failures": []
}

5. 映射 mappings

查询映射

GET test_index/_mapping

输出

{"test_index": {"mappings": {"properties": {"alisa": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"name": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"value": {"type": "long"}}}}
}

查看单个字段的属性

GET test_index/_mapping/field/value

输出

{"test_index": {"mappings": {"value": {"full_name": "value","mapping": {"value": {"type": "long"}}}}}
}

6. 自动映射

dynamic mappings
建立 index 的时候没有设置 mapping,根据你的 value 自动推断类型

ES 不支持修改字段类型、没有隐式转换(比如 “123” 不会当成 数字 123)、建议指定 mapping

7. 显式映射

PUT test_index1
{"mappings": {"properties": {"price": {"type": "float"},"name": {"type": "keyword"},"desc": {"type": "text"}}}
}

查看 mapping

GET test_index1/_mapping

数据类型 见 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html

映射参数
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html

  • coerce,是否允许强制类型转换
  • copy_to,把字段的值 copy 到对应字段中,不可见,但是可查
  • doc_values,设置为 false ,不能对该字段进行排序,聚合查询,可以减少磁盘占用
  • enable,index 是否被索引,或者 object 字段是否被索引
  • ignore_above,对超过长度的字段,搜索时无法搜索到
  • index,字段是否可以被索引
  • fields,可以创建多个子字段
  • norms,是否禁用评分(评分可用来排序)
  • store,加速查询 store 过的字段

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/470827.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ACM/ICPC 之 四道MST-Prim解法(POJ1258-POJ1751-POJ2349-POJ3026)

四道MST&#xff0c;适合Prim解法&#xff0c;也可以作为MST练习题。 题意包括在代码中。 POJ1258-Agri Net 水题 1 //Prim-没什么好说的2 //接受一个邻接矩阵&#xff0c;求MST3 //Time:0Ms Memory:220K4 #include<iostream>5 #include<cstring>6 #include<…

二、bootstrap4基础(flex布局)

1.1 Flex弹性布局&#xff08;一&#xff09; <div class"d-flex flex-column border border-danger justify-content-end mb-5" style"height: 200px;"><div class"p-2 border border-success">one</div><div class"…

《数据结构与算法之美》学习汇总

此篇文章是对自己学习这门课程的一个总结和课后的一些练习&#xff0c;做一个汇总&#xff0c;希望对大家有帮助。本人是半路程序员&#xff0c;2018年2月开始学习C的&#xff0c;下面的代码基本都是C11版本的&#xff0c;代码有错误的地方请不吝留言赐教。附有部分练习LeetCod…

android简单的夜间模式

现在android项目values下打 attrs.xml <?xml version"1.0" encoding"utf-8"?> <resources><attr name"bookimage" format"reference|color" /><attr name"tvcolor" format"reference|color&quo…

三、bootstrap4 组件(警告和提示框、徽章和面包屑、按钮按钮组、卡片、列表组、导航和选项卡、分页和进度条、巨幕和旋转图标、轮播图、折叠菜单、下拉菜单、导航条、滚动监听、轻量弹框、模态框、表单)

1.1 警告提示框 1.2 徽章和面包屑 1.3 按钮和按钮组 1.4 卡片 1.5 列表组 1.6 导航和选项卡 1.7 分页和进度条 1.8 巨幕和旋转图标 1.9 轮播图 1.10 折叠菜单 1.11 下拉菜单 <!DOCTYPE html> <html><head><meta charset"utf-8" /><title&…

吴恩达-《深度学习DeepLearning》汇总目录

从2019年2月底开始学习《数据结构与算法之美》&#xff0c;王争老师的课程非常好&#xff0c;到2019年8月底已经学完一遍&#xff0c;后面还要多次复习巩固以及OJ刷题。生命不息&#xff0c;学习不止&#xff0c;又要开始新的篇章了–《机器学习》&#xff0c;有点小兴奋&#…

javascript常用内置对象总结(重要)

Javascript对象总结 JS中内置了17个对象&#xff0c;常用的是Array对象、Date对象、正则表达式对象、string对象、Global对象 Array对象中常用方法&#xff1a; Concat&#xff08;&#xff09;&#xff1a;表示把几个数组合并成一个数组。 Join&#xff08;&#xff09;&#…

十三、axios框架学习

一、axios的基本使用 1.1 安装axios 执行命令&#xff1a;npm install axios --save 1.2 发送get请求演示 1.3 发送并发请求 有时候, 我们可能需求同时发送两个请求 使用axios.all, 可以放入多个请求的数组.axios.all([]) 返回的结果是一个数组&#xff0c;使用 axios.sp…

LeetCode解题汇总目录

此篇为学习完《数据结构与算法之美》后&#xff0c;在LeetCode刷题的汇总目录&#xff0c;方便大家查找&#xff08;CtrlFind&#xff09;&#xff0c;一起刷题&#xff0c;一起PK交流&#xff01;如果本文对你有帮助&#xff0c;可以给我点赞加油&#xff01; Updated on 2022…

java——IO流整理(一)

一、基础 1.字节、字符 位&#xff08;bit&#xff09;   &#xff1a;二进制中的一个1或0称为1位字节&#xff08;byte&#xff09; &#xff1a;8个二进制位称为一个字节字符     &#xff1a;一个自然符号称为字符。英文符号&#xff08;1个字节&#xff09;、中文符…

Node.js学习笔记

Node介绍 为什么要学习Node.js 企业需求 具有服务端开发经验更改front-endback-end全栈开发工程师基本的网站开发能力 服务端前端运维部署 多人社区 Node.js是什么 Node.js是JavaScript 运行时通俗易懂的讲&#xff0c;Node.js是JavaScript的运行平台Node.js既不是语言&am…

《统计学习方法》学习笔记目录

此篇为 李航老师著的《统计学习方法》的学习笔记汇总&#xff0c;准备学习并敲一敲代码&#xff0c;还请大家不吝赐教&#xff01;updated on 2020.4.26 一些相关的实践&#xff1a;请查阅机器学习 1. 统计学习及监督学习概论 2. 感知机&#xff08;Perceptron&#xff09; …

iOS: 属性声明strong和retain竟然不一样

今天和同事在处理一处用strong声明的Block属性引发的问题时偶然发现的。在诸多教程中都会讲到&#xff1a;声明属性时用strong或者retain效果是一样的&#xff08;貌似更多开发者更倾向于用strong&#xff09;。不过在声明Block时&#xff0c;使用strong和retain会有截然不同的…

一、node.js搭建最简单的服务器

node.js搭建最简单的服务器 代码演示&#xff1a; // 1. 加载http核心模块 var http require(http)// 2. 使用http.createServer()方法创建一个Web服务器 // 返回一个Server实例 var server http.createServer()// 3. 服务器干嘛&#xff1f; // 提供服务&#xff1a; 对数…

DDD 领域驱动设计-如何 DDD?

注&#xff1a;科比今天要退役了&#xff0c;我是 60 亿分之一&#xff0c;满腹怀念&#xff5e;??? 前几天看了园友的一篇文章《我眼中的领域驱动设计》&#xff0c;文中有段话直击痛点&#xff1a;有人误认为项目架构中加入 Repository&#xff0c;Domain&#xff0c;Valu…

二、搭建Apache服务器 模板引擎

1. 案例&#xff1a;搭建简单的Apache服务器 var http require(http) var fs require(fs)var server http.createServer()var wwwDir D:\\CWork\\node.js黑马程序员\\study_nodejs\\day02\\code\\wwwserver.on(request, function(req, res) {var url req.urlfs.readFile(…

三、案例:留言板 url.parse()

1. url.parse()的使用 2. 留言板案例 index.html: <!DOCTYPE html> <!-- saved from url(0027)http://192.168.150.76:3000/ --> <html lang"en"><head><meta http-equiv"Content-Type" content"text/html; charsetUTF-8…

iOS开发——收集Github上的iOS控件和开发资料

https://github.com/JanzTam/MyGithubMark转载于:https://www.cnblogs.com/adople/p/5391912.html

四、模块系统

什么是模块化 文件作用域(模块是独立的&#xff0c;在不同的文件使用必须要重新引用)【在node中没有全局作用域&#xff0c;它是文件模块作用域】通信规则 加载require导出exports CommonJS模块规范 在Node中的JavaScript还有一个重要的概念&#xff0c;模块系统。 模块作用…

Jquery 实现原理之 Ajax

一&#xff1a;Jquery Ajax底层接口有&#xff1a;$.ajaxPrefilters、$.ajaxTransport、$.ajaxSettings、$ajaxSetup、$ajaxSettings; 其中$.ajaxPrefilters 和 $.ajaxTransport是通过inspectPrefiltersOrTransports构造器来创建的; $.ajaxPrefilters&#xff1a;是一个前置过滤…