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"
}
}

转载于:https://www.cnblogs.com/studyitskill/p/7804451.html

elasticsearch 基础语句相关推荐

  1. ElasticSearch基础杂烩-配置-索引-优化

    2019独角兽企业重金招聘Python工程师标准>>> ElasticSearch基础杂烩-配置-索引-优化 博客分类: java 前言 ElasticSearch是一个基于Luce ...

  2. Elasticsearch基础教程ES

    Elasticsearch基础教程     翻译:潘飞(tinylambda@gmail.com) 基础概念 Elasticsearch有几个核心概念.从一开始理解这些概念会对整个学习过程有莫大的帮助 ...

  3. Elasticsearch基础1——搜索引擎发展史和工作流程、es/es-head/kibana的基础安装

    文章目录 一.搜索引擎 1.1 搜索引擎的发展背景 1.2 Lucene和Elasticsearch 1.3 Solr和Elasticsearch对比 1.4 数据搜索方式 1.5 搜索引擎 1.5. ...

  4. elasticsearch 基础介绍及使用 (high-level-client)

    目录 一.ElasticSearch 简介 二.ElasticSearch 基础概念 三.SpringBoot 项目引入 ElasticSearch 依赖 1.Maven 引入相关依赖 2.Elast ...

  5. ElasticSearch 基础(四)之 常用 API 测试

    目录 前言 一.查看(Cat) API 1.查看节点信息 2.查看各节点机器存储信息 3.查询索引信息 4.查询分片信息 5.查询集群健康状态 6.查询集群所有的别名索引 7.查询主节点信息 8.查询 ...

  6. mysql 截断表_入门MySQL——基础语句篇

    前言: 前面几篇文章,我们介绍了MySQL的基础概念及逻辑架构.相信你现在应该有了自己的一套MySQL环境,接下来我们就可以开始练习MySQL了.本文将从MySQL最基础的语句出发,为你展示出创建及修 ...

  7. Elasticsearch 基础入门

    原文地址:Elasticsearch 基础入门 博客地址:http://www.extlight.com 一.什么是 ElasticSearch ElasticSearch是一个基于 Lucene 的 ...

  8. vba 不等于_EXCEL中VBA基础语句(1)

    萌二笔记分类目录及书单 一.If-Then语句 说明:条件判断,如果......那么......例1:A2单元格的成绩大于等于60,则弹出对话框提示"及格". Sub 判断成绩() ...

  9. mysql数据库基础语句讲解

    mysql数据库基础讲解 一.数据库客户端命令 二.数据库基础sql语句 三.数据表基础语句 四.数据的增删改查(重点) 切记sql语句之后一定要加 ; 一.数据库客户端命令 1.mysql: mys ...

最新文章

  1. 使最新版Code::Blocks支持C++11标准
  2. redis 亿级查询速度_Redis 性能优化的 13 条军规!史上最全
  3. 学习Guava Cache知识汇总
  4. 内存泄漏normal block at
  5. 【心灵鸡汤】高情商者的15个表现
  6. 计算机桌面组成部分教案,计算机基础 教案设计(完整版).doc
  7. VC内存泄露检查工具:VisualLeakDetector
  8. Java-Jdbc,JDBC连接Oracle11g实例:
  9. 程序员的思维修炼》读书笔记
  10. C/C++ strtod函数 - C语言零基础入门教程
  11. shell脚本批量导出MYSQL数据库日志/按照最近N天的形式导出二进制日志[连载之构建百万访问量电子商务网站]...
  12. 自己做的一个简历网页,有很多bug解决不了,有没有大神帮我看看
  13. mongodb java 地理位置_MongoDB的地理位置索引
  14. 想起“不能什么都是你来干”
  15. opencv读取视频,读取摄像头
  16. python随堂笔记(2)- globle全局变量的修改
  17. 星际争霸2中文版下载 – 即时战略游戏超大作 (繁体含中文语音)
  18. 面向对象使用python-docx模块制作格式化文本(奖状生成器)
  19. 微软官方精简Windows7系统——Windows Thin PC的安装过程
  20. 2023北京叶黄素展/北京视力矫正设备展/北京眼睛医学康复展

热门文章

  1. sql中like带参数的写法
  2. 整数行hdu 1244 Max Sum Plus Plus Plus(dp)
  3. wcf ria中主从表绑定treeview
  4. android service 学习(上)
  5. tushare 金融数据获取(R语言版)
  6. 山东科技大学计算机控制系统期末考试试卷,山东科技大学_计算机操作系统试题A...
  7. iphone连上wifi却上不了网_必收藏为什么手机信号满格,却上不了网,4招为你解决...
  8. Android图片褪色,Android – 使用Alpha褪色动画闪烁图片
  9. ping ip 端口_学生会私房菜【20200305期】——Ping命令及其常用参数详解
  10. php 获取url文件名,php 获取当前访问的url文件名的方法小结