五、Elasticsearch-Index API

2019-07-10  本文已影响0人  ASD_92f7

一、概述

本篇主要翻译官网的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上原文吧

上一篇 下一篇

猜你喜欢

热点阅读