美文网首页
五、Elasticsearch-Index API

五、Elasticsearch-Index API

作者: ASD_92f7 | 来源:发表于2019-07-10 16:45 被阅读0次

一、概述

本篇主要翻译官网的index相关的API
index:索引,后续不再翻译
参考链接:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#_version_types

二、APIs

1、Automatic Index Creation 自动创建index

// 允许twitter、index10及与ind*匹配的请求自动创建index
//不允许与index1*匹配的创建索引
PUT _cluster/settings
{
    "persistent": {
        "action.auto_create_index": "twitter,index10,-index1*,+ind*" 
    }
}
// 不允许自动创建索引
PUT _cluster/settings
{
    "persistent": {
        "action.auto_create_index": "false" 
    }
}
//允许自动创建索引
PUT _cluster/settings
{
    "persistent": {
        "action.auto_create_index": "true" 
    }
}

2、Operation Type 操作类型

PUT twitter/_doc/1?op_type=create
// 等价于
PUT twitter/_create/1

这个时候,如果文档的id已经存在,则会报错

3、Automatic ID Generation 自动生成文档ID

使用POST方式即可

POST twitter/_doc/

4、Optimistic concurrency control 乐观锁机制控制并发

采用类似数据库乐观锁的机制,每次写入都会附带一个版本号

5、Routing 路由

默认情况下,写入的时候,es会根据文档的id做hash分配响应的shard,并由shard所在的node完成数据的写入,当然,也可以手工指定路由

POST twitter/_doc?routing=kimchy

5、Distributed 分发

primary写入完成后,会分发给repila进行写入

6、Wait For Active Shards 等待可用的片

默认情况下,wait_for_active_shards=1,即只要primary shard或者就可以写入
当然,也可以修改为不大于index下所有shards的一个数,比如有1个primay,3个repila,那么wait_for_active_shards最大是1+3=4个,超过这个数字会报错,如果设置为3,那么只要有1个primary和2个repila活着就允许写入,如果这个时候有一个repila挂了,那么这个写入操作就会等待master重新拉起来一个repila,或者等待超时返回错误。

7、Refresh 刷新

这个应该是保证本次写入后,repila一定能同步吧,用到再说吧

8、Noop Updates 空更新

在 Index API中,每次针对文档的更新,都会产生一个版本号,就算你什么都没有修改,如果不想修改,那么需要使用 Update API,并且设置detect_noop=true

9、Timeout 超时

默认的超时时间是1分钟?也可以自己设置,下面就将超时时间设置成了5分钟

PUT twitter/_doc/1?timeout=5m

10、Versioning 版本

可以显示地指定本次操作的版本

PUT twitter/_doc/1?version=2&version_type=external

上面的version=2,如果再执行版本号 <= 2的,如下面的url,会报错

PUT twitter/_doc/1?version=1&version_type=external

11、Version Type 版本类型

不太理解,先copy上原文吧

  • internal
    Only index the document if the given version is identical to the version of the stored document.
  • external or external_gt
    Only index the document if the given version is strictly higher than the version of the stored document or if there is no existing document. The given version will be used as the new version and will be stored with the new document. The supplied version must be a non-negative long number.
  • external_gte
    Only index the document if the given version is equal or higher than the version of the stored document. If there is no existing document the operation will succeed as well. The given version will be used as the new version and will be stored with the new document. The supplied version must be a non-negative long number.

相关文章

  • 五、Elasticsearch-Index API

    一、概述 本篇主要翻译官网的index相关的APIindex:索引,后续不再翻译参考链接:https://www....

  • 13-Runtime(API)

    一、API(类) 二、API(成员变量) 三、API(属性) 四、API(方法) 代码 五、API(Runtime...

  • [6]elasticsearch源码深入分析——API源码分析

    上一篇中我们讲到ElasticSearch中分为五类API(查看API,文档API,搜索API,索引API,集群A...

  • Sawtooth Lake学习笔记(十)

    五、REST API Sawtooth提供了REST API(请参阅REST API参考),它允许客户端通过常用的...

  • 五、REST API

    参考: https://www.liaoxuefeng.com/wiki/001434446689867b2715...

  • 五、数组API

    一、数组的判断 arr instance Array; Array.isArray(arr); 方法: 1. pu...

  • 五 Stream API

    Java8中有两大最为重要的改变。第一个是 Lambda 表达式;另外一个则是 Stream API( java....

  • ActiveMQ-API(五)

    负载均衡(取模做负载均衡)简单利用线程实现吞吐量栗子实现:

  • Appium常用API(五)

    appium的客户端(WebDriver)提供的接口按作用分为: 1、系统操作 2、获取和操作控件信息 3、控件查...

  • Redis(五)-- Java API

    一、pox.xml 二、Java代码,Jedis工具类 欢迎关注我的公众号,第一时间接收文章推送~ 搜索公众号: ...

网友评论

      本文标题:五、Elasticsearch-Index API

      本文链接:https://www.haomeiwen.com/subject/pdphkctx.html