elasticsearch 基础语句
1. doucument id 的两种生成方式
自动生成document id
自动生成的id,长度为20个字符,URL安全,base64编码,GUID,分布式系统并行生成时不可能会发生冲突
POST /test_index/test_type (这里没有标识id)
{
"test_content": "my test"
}
GET /test_index/test_type/_search
手动指定document id
PUT /test_index/test_type/2
{
"test_content":"ding-jiang"
}
GET /test_index/test_type/2
注意点:1 我们的{}不能和 PUT写到一行 否则会报错 failed to parse, document is empty
2 GET /test_index/test_type/_search 会得到该节点下所有的数据列表
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. doucument的_source元数据以及定制返回结果解析
put /test_index/test_type/1
{
"test":"test11",
"test1":"test22"
}
GET /test_index/test_type/1
返回
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"test": "test11",
"test1": "test22"
}
}
_source元数据:就是创建document时我们存入的数据
如果我们不想返回全部的数据,只想返回一部分数据,比如有test 和test11 而我们只用test那么
GET /test_index/test_type/1?_source=test 则_source只返回
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"test": "test11"
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
3. doucument的全量替换 强制创建和 delete 机制
1、document的全量替换
(1)语法与创建文档是一样的,如果document id不存在,那么就是创建;如果document id已经存在,那么就是全量替换操作,替换document的json串内容
(2)document是不可变的,如果要修改document的内容,第一种方式就是全量替换,直接对document重新建立索引,替换里面所有的内容
(3)es会将老的document标记为deleted,然后新增我们给定的一个document,当我们创建越来越多的document的时候,es会在适当的时机在后台自动删除标记为deleted的document
就是说全量替换会将_source的内容替换,但是之前的内容并没有从库中删除而是被标记为了deleted,es在恰当的时候会在动删除这些deleted数据(document)
创建的标识就是GET /test_index/test_type/1 中的_version会加1
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 3,
"found": true,
"_source": {
"test": "test11",
"test1": "test22",
"test_version": 3
}
}
2. 强制创建
(1)创建文档与全量替换的语法是一样的,有时我们只是想新建文档,不想替换文档,如果强制进行创建呢?
PUT /test_index/test_type/1/_create
{
"test333":"ding"
}
会报错 因为id是不能重复的 如果我们想创建那么id必须修改
{
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[test_type][1]: version conflict, document already exists (current version [3])",
"index_uuid": "XtO4uL9HTo2v34qmximdLg",
"shard": "3",
"index": "test_index"
}
],
"type": "version_conflict_engine_exception",
"reason": "[test_type][1]: version conflict, document already exists (current version [3])",
"index_uuid": "XtO4uL9HTo2v34qmximdLg",
"shard": "3",
"index": "test_index"
},
"status": 409
}
3. 删除
DELETE /test_index/test_type/11
GET /test_index/test_type/11
这个和全量替换一样不会立即物理删除,只会将其标记为deleted,当数据越来越多的时候,在后台自动删除
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 partial update
什么是partial update?
PUT /index/type/id,创建文档&替换文档,一样的语法
post /index/type/id/_update
{
"doc": {
"要修改的少数几个field即可,不需要全量的数据"
}
}
例如:
POST /test_index/test_type/8/_update
{
"doc":{
"test_field":"partial update",
"test2":"test22"
}
}
GET /test_index/test_type/8
{
"_index": "test_index",
"_type": "test_type",
"_id": "8",
"_version": 7,
"found": true,
"_source": {
"test_field": "partial update",
"test2": "test22"
}
}
elasticsearch 基础语句的更多相关文章
- ELK(elasticsearch+kibana+logstash)搜索引擎(二): elasticsearch基础教程
1.elasticsearch的结构 首先elasticsearch目前的结构为 /index/type/id id对应的就是存储的文档ID,elasticsearch一般将数据以JSON格式存储. ...
- MySQL 基础语句
MySQL 基础语句 多个知识点 ----------------------------------------------------------------------------------- ...
- MySQL基础语句与其在Python中的使用
一.MySQL基础语句 $ mysql -u root -p (有密码时) $ mysql -u root (无密码时) QUIT (or \q) 退出 查看当前所有数据库 show dat ...
- T——SQL基础语句(定义变量,赋值,取值,分支,循环,存储过程)
T--SQL基础语句 1.定义变量: declare @变量名 数据类型 ; declare @a int ; declare @b nvarchar(10) ; 2.赋值: 法1:set @变量名 ...
- 【2017-03-10】T-sql基础语句及条件,高级查询
一.T-sql基础语句 1.创建数据库:create database 数据库名 (不能中文,不能数字开头,不能符号开头) 2.删除数据库:drop database 数据库名 3.选择数据库:us ...
- Elasticsearch 基础入门
原文地址:Elasticsearch 基础入门 博客地址:http://www.extlight.com 一.什么是 ElasticSearch ElasticSearch是一个基于 Lucene 的 ...
- 10-14C#基础--语句(switch....case和for...循环)
10-14C#基础--语句(2) 一.课前作业:“跟电脑猜拳” 二.switch(定义的变量,参数值)......case.... 注:switch...case大多用于值类型的判断,这里不同于if表 ...
- 入门MySQL——基础语句篇
前言: 前面几篇文章,我们介绍了MySQL的基础概念及逻辑架构.相信你现在应该有了自己的一套MySQL环境,接下来我们就可以开始练习MySQL了.本文将从MySQL最基础的语句出发,为你展示出创建及 ...
- ElasticSearch 基础 1
ElasticSearch 基础=============================== 索引创建 ========================== 1. RESTFUL APIAPI 基本 ...
随机推荐
- C# JAVA成员访问修饰符比较
在面向对象的访问修饰符中常用的有public ,private ,protected C# 访问修饰符: private < protected internal < internal/p ...
- Maven打包Jar
现状 该项目使用了Maven,并且引入了Spring,包含代码.配置文件.Jar包,使用的是IDEA来作为开发工具,项目的产出物是要打包成一个可运行的Jar包.通过IDEA的打包工具也可以打包成功,只 ...
- VTL(Velocity Templates Language,即Velocity模板语言)初识语法总结
1.velocity是一门基于Java语言的视图表现层模板引擎,它可以取代jsp,比jsp更高效. 2.velocity变量的定义与引用 (1).定义一个变量:#set ($a = "vel ...
- python之testcenter操作
一.设置python环境 1. 从以下路径中将StcPython.py文件拷贝出来 Linux: /Installdir/Spirent_TestCenter_4.xx/Spirent_TestCen ...
- JAVA提高三:反射总结
为前期学习过反射,再这里再次复习总结下:[转载请说明来源:http://www.cnblogs.com/pony1223/p/7659210.html ] 一.透彻分析反射的基础_Class类 Cla ...
- WPF自定义命令和处发命令
接实现ICommand接口的命令.在介绍之前,先看一下ICommand接口的原型: event EventHandler CanExecuteChanged; bool CanExecute(obje ...
- 干了这杯Java之LinkedList
LinkedList和ArrayList一样实现了List接口 ArrayList内部为数组 LinkedList内外为双向链表 实现了Deque接口,双端列队的实现 图片来自Wiki 内部实现为No ...
- UWP 手绘视频创作工具技术分享系列 - 位图的绘制
前面我们针对 SVG 的解析和绘制做了介绍,SVG 是图片的一种形式,而另一种很重要的图片是:位图,包括 png.jpeg.bmp 等格式.位图的基本规则是,组成的基本元素是像素点,由宽度 * 高度个 ...
- (10.16)java小作业!
相信大家刚刚学习java多多少少都会写一些java的基础编程来练练手感,我也不例外!今天想和大家分享一下我最近所接触到的比较有趣的java小编程! 已知a已被赋值,b已被赋值,请编写java程序实现a ...
- 【特效】hover图片立体翻转
hover图片翻转效果二::绕Y轴旋转90度,注意父层要加透视属性perspective,这样才能看出立体效果 html: <ul class="list-img"> ...