1.自动创建索引控制

  Automatic index creation is controlled by the action.auto_create_index setting. This setting defaults to true, meaning that indices are always automatically created. Automatic index creation can be permitted only for indices matching certain patterns by changing the value of this setting to a comma-separated list of these patterns. It can also be explicitly permitted and forbidden by prefixing patterns in the list with a + or -. Finally it can be completely disabled by changing this setting to false.

  意思是:

    默认是true,会自动创建索引。

    可以配合通配符,决定哪些配置可以被创建,哪些配置不允许被创建

    可以设置false,完全禁止设置

  测试:

 PUT _cluster/settings
{
"persistent": {
"action.auto_create_index": "twitter,index10,-index1*,+ind*"
}
} POST ind1/dov/1
{
"score":"10"
}

  说明:

    Permit only the auto-creation of indices called twitterindex10, no other index matching index1*, and any other index matching ind*. The patterns are matched in the order in which they are given.

  效果:

 #! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
{
"_index" : "ind1",
"_type" : "dov",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}

  再执行:

 POST /index11/doc/1
{
"score":"10"
}

  效果:

#! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [index11] and [action.auto_create_index] contains [-index1*] which forbids automatic creation of the index",
"index_uuid" : "_na_",
"index" : "index11"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [index11] and [action.auto_create_index] contains [-index1*] which forbids automatic creation of the index",
"index_uuid" : "_na_",
"index" : "index11"
},
"status" : 404
}

  再次恢复默认:

 PUT _cluster/settings
{
"persistent": {
"action.auto_create_index": "true"
}
}

  返回:

 {
"acknowledged" : true,
"persistent" : {
"action" : {
"auto_create_index" : "true"
}
},
"transient" : { }
}

2.版本控制

  ES提供了版本控制,可以通过使用版本查询参数来指定文档的特定版本。

  内部的版本控制是默认版本,从1开始,每次更新递增,包括删除。版本号可以在外部设置,不过要启用此功能,需要将version_type设置为外部。

  版本控制是一个实时的过程,不受实时搜索操作的影响。

  修改过下面的信息:

 PUT index1/_doc/1
{
"name":"tom1",
"sex":"M"
}

  查看:

 GET index1/_doc/1

  返回:

 {
"_index" : "index1",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 3,
"found" : true,
"_source" : {
"name" : "tom1",
"sex" : "M"
}
}

  发现上面是version为2,所以,可以使用version进行过滤:

 GET index1/_doc/1?version=2

  效果与上面的执行结果相同。

  关于版本version_type的功能,后续明白了再补充。

4.操作类型

  The index operation also accepts an op_type that can be used to force a create operation, allowing for "put-if-absent" behavior. When create is used, the index operation will fail if a document by that id already exists in the index.

  意思是:用于强制创建操作,如果存在,则操作失败,避免覆盖现有的文档.

  我的理解是,不会再允许创建了,version不会进行叠加了,只会报错。但是如果再去掉,马上又可以进行更新掉,version进行叠加。

 GET /_cat/indices
DELETE /twitter/
PUT twitter/_doc/1?op_type=create
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}

  一次创建:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}

  再次创建:

 {
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[1]: version conflict, document already exists (current version [1])",
"index_uuid": "Cp1z9uTRRhG0wIV2XiJPpQ",
"shard": "0",
"index": "twitter"
}
],
"type": "version_conflict_engine_exception",
"reason": "[1]: version conflict, document already exists (current version [1])",
"index_uuid": "Cp1z9uTRRhG0wIV2XiJPpQ",
"shard": "0",
"index": "twitter"
},
"status": 409
}

5.自动生成ID

  The index operation can be executed without specifying the id. In such a case, an id will be generated automatically. In addition, the op_type will automatically be set to create. Here is an example (note the POST used instead of PUT)

 ID自动生成
POST twitter/_doc/
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}

  结果:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "cI7jS2wBE-J5sxKYhB25",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 50,
"_primary_term" : 1
}

  说明:POST这种多次提交,id在一直变化,但是version不会变化。

     但是PUT,id不会变化,version一直在变。

  

005 文档API的更多相关文章

  1. jQuery全屏滚动插件fullPage.js中文帮助文档API

    jQuery全屏滚动插件fullPage.js中文帮助文档API   发现了一个fullPage.js插件,于是百度了一下,还就是这个插件的作用,其实有很多网站都做了全屏滚动的特效,效果也很好看,今天 ...

  2. 百度地图和高德地图坐标系的互相转换 四种Sandcastle方法生成c#.net帮助类帮助文档 文档API生成神器SandCastle使用心得 ASP.NET Core

    百度地图和高德地图坐标系的互相转换   GPS.谷歌.百度.高德坐标相互转换 一.在进行地图开发过程中,我们一般能接触到以下三种类型的地图坐标系: 1.WGS-84原始坐标系,一般用国际GPS纪录仪记 ...

  3. 大数据相关文档&Api下载

    IT相关文档&Api下载(不断更新中) 下载地址:https://download.csdn.net/user/qq_42797237/uploads 如有没有你需要的API,可和我留言,留下 ...

  4. GrapeCity Documents (服务端文档API组件) V3.0 正式发布

    近日,葡萄城GrapeCity Documents(服务端文档API组件)V3.0 正式发布! 该版本针对 Excel 文档.PDF 文档和 Word 文档的 API 全面更新,加入了用于生成 Exc ...

  5. GrapeCity Documents for Excel 文档API组件 V2.2 新特性介绍

    GrapeCity Documents for Excel 文档API组件 V2.2 正式发布,本次新版本包含诸多重量级产品功能,如:将带有形状的电子表格导出为 PDF.控制分页和电子表格内容.将Ex ...

  6. [转载]Android SDK 离线文档 (api 20)(升级至api 23)

    原文地址:SDK 离线文档 (api 20)(升级至api 23)">Android SDK 离线文档 (api 20)(升级至api 23)作者:leechenhwa Android ...

  7. Openstack python api 学习文档 api创建虚拟机

    Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...

  8. 文档API生成神器SandCastle使用心得

    一.功能描述 关于Sandcastle网上的参考资料相对较少,Google出来很多资料都是全英文的,相对于我这种英语渣渣看起来还是很费劲的. 言简意赅,Sandcastle主要功能是能够将C#类生成类 ...

  9. java.net.URI 简介 文档 API

    URI 简介 文档地址:http://tool.oschina.net/apidocs/apidoc?api=jdk-zh public final class java.net.URI extend ...

随机推荐

  1. Flink使用(二)——Flink集群资源规划

    前言 本文主要译自Flink Forward 2017的柏林站中Robert Metzger的有关集群规划的How to size your flink cluster一文.该文中主要是考虑网络资源, ...

  2. Photozoom图像放大的技术一二事

    平行空间下,未知的可能不仅仅是这个世界,还可能是前所未有的未知的探索.那么对于微小型世界来说,我们就需要借助技术的支撑来发现.photozoom就好比是“电子的放大镜”,对我们清晰图像的放大起到了重要 ...

  3. SpringCloud2.0 Config 分布式配置中心 基础教程(十一)

    Spring Cloud Config 简介 Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外 ...

  4. Sharding-JDBC(二)2.0.3版本实践

    目录 一.Sharding-JDBC依赖 二.分片策略 1. 标准分片策略 2. 复合分片策略 3. Inline表达式分片策略 4. 通过Hint而非SQL解析的方式分片的策略 5. 不分片的策略 ...

  5. 《CoderXiaoban》第九次团队作业:Beta冲刺与验收准备2

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验十三 团队作业9:BETA冲刺与团队项目验收 团队名称 Coderxiaoban团队 作业学习目标 (1)掌握软件黑盒 ...

  6. Java - Annotation使用

    本文转载于(这个写的很好):https://www.cnblogs.com/be-forward-to-help-others/p/6846821.html Annotation Annotation ...

  7. 织梦cmsf表单提交到邮箱 织梦表单发送到邮箱 织梦自定义表单发邮箱

    大家在做织梦做网站开发时会遇到一个问题:织梦的自定义表单是一个很鸡肋的功能,不仅在后台展示得奇丑,而且也没有提醒功能,使用起来很不方便.很多人用织梦自定义表单时,都想用户提交表单的时候可以发送到自己的 ...

  8. keepalived 的 vrrp_script

    [root@centos01 keepalived]# cat check_httpd.sh 脚本需要有执行权限 通常情况下,利用keepalived做热备,其中一台设置为master,一台设置为ba ...

  9. Hello 2019【A,B,C】

    #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string str; ...

  10. YAML_15 include and roles

    在编写playbook的时候随着项目越来越大,playbook越来越复杂.可以把一些play.task 或 handler放到其他文件中,通过包含进来是一个不错的选择. roles像是加强版的incl ...