1. index creation
- 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. Add the field
- PUT index/_mapping
- {
- "properties":{
- "Index": {
- "type":"date",
- "format":"yyyy-MM-dd HH:mm:ss"
- }
- }
- }
3. Delete Index
- DELETE index
4. The opening / closing Index
4.1 Opening index
- POST index/_open
Index closed 4.2
- POST index/_close
5. rebuild the index
- 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"
- }
- }
Description:
- version_type
- internal: represents the migration of all data, and complete coverage of the conflict document (even if the target version of the new document in the source document index).
- external: represents the migration of all data, documents and more old and new versions conflict.
- op_type:
- create: document represents only create target index does not exist.
6. Alias Management
6.1 add an alias
- POST /_aliases
- {
- "actions":[
- {
- "add":{
- "index":"indexName1",
- "alias":"aliasName"
- }
- },
- {
- "add":{
- "index":"indexName2",
- "alias":"aliasName"
- }
- }
- ]
- }
6.2 Delete alias
- POST /_aliases
- {
- "actions":[
- {
- "remove":{
- "index":"indexName",
- "alias":"aliasName"
- }
- }
- ]
- }
6.3 Renaming
- POST /_aliases
- {
- "actions":[
- {
- "remove":{
- "index":"indexName",
- "alias":"aliasName1"
- }
- },
- {
- "add":{
- "index":"indexName",
- "alias":"aliasName2"
- }
- }
- ]
- }
7. merge index
- POST index/_forcemerge?max_num_segments=1
8. narrow index
8.1 first index is set to read-only
- PUT source_index/_setting
- {
- "settings":{
- "index.routing.allocation.require._name":"node-1",
- "index.blocks.write":true
- }
- }
8.2 execution shrink
- POST source_index/_shrink/target_index
- {
- "settings":{
- "index.number_of_replicas":1,
- "index.number_of_shards":1,
- "index.codec":"best_compression"
- }
- }
Article from: java architecture