1. 索引创建
- PUT index
- {
- "settings":{
- "number_of_shards":3,
- "number_of_replicas":1
- },
- "mappings":{
- "properties":{
- "title":{
- "type":"text",
- "analyzer":"ik_max_words",
- "search_analyzer":"ik_smart"
- },
- "tag":{
- "type":"keyword"
- }
- }
- }
- }
2. 添加字段
- PUT index/_mapping
- {
- "properties":{
- "indexAt":{
- "type":"date",
- "format":"yyyy-MM-dd HH:mm:ss"
- }
- }
- }
3. 删除索引
- DELETE index
4. 打开/关闭索引
4.1 打开索引
- POST index/_open
4.2 关闭索引
- POST index/_close
5. 重建索引
- POST /_reindex
- {
- "source":{
- "index":"sourceIndexName",
- "query":{
- },
- "sort":{
- "fieldName":"asc/desc"
- },
- "size":5000,
- "_source":[
- "fieldName1",
- "fieldName2",
- "fieldName3",
- ]
- },
- "dest":{
- "index":"destIndexName",
- "version_type":"internal(default)/external",
- "op_type":"create"
- }
- }
说明:
- version_type
- internal:表示迁移全部数据,且完全覆盖冲突文档(即使目标文档版本新于源索引文档)。
- external:表示迁移全部数据,且更新旧版本冲突文档。
- op_type:
- create:表示仅创建目标索引不存在的文档。
6. 别名管理
6.1 添加别名
- POST /_aliases
- {
- "actions":[
- {
- "add":{
- "index":"indexName1",
- "alias":"aliasName"
- }
- },
- {
- "add":{
- "index":"indexName2",
- "alias":"aliasName"
- }
- }
- ]
- }
6.2 删除别名
- POST /_aliases
- {
- "actions":[
- {
- "remove":{
- "index":"indexName",
- "alias":"aliasName"
- }
- }
- ]
- }
6.3 重命名
- POST /_aliases
- {
- "actions":[
- {
- "remove":{
- "index":"indexName",
- "alias":"aliasName1"
- }
- },
- {
- "add":{
- "index":"indexName",
- "alias":"aliasName2"
- }
- }
- ]
- }
7. 合并索引
- POST index/_forcemerge?max_num_segments=1
8. 缩小索引
8.1 先把索引设置为只读
- PUT source_index/_setting
- {
- "settings":{
- "index.routing.allocation.require._name":"node-1",
- "index.blocks.write":true
- }
- }
8.2 执行shrink
- POST source_index/_shrink/target_index
- {
- "settings":{
- "index.number_of_replicas":1,
- "index.number_of_shards":1,
- "index.codec":"best_compression"
- }
- }
文章来自:java架构