es index management

1. index creation

  1. PUT index
  2. {
  3. "settings":{
  4. "number_of_shards":3,
  5. "number_of_replicas":1
  6. },
  7. "mappings":{
  8. "properties":{
  9. "title":{
  10. "type":"text",
  11. "analyzer":"ik_max_words",
  12. "search_analyzer":"ik_smart"
  13. },
  14. "tag":{
  15. "type":"keyword"
  16. }
  17. }
  18. }
  19. }

2. Add the field

  1. PUT index/_mapping
  2. {
  3. "properties":{
  4. "Index": {
  5. "type":"date",
  6. "format":"yyyy-MM-dd HH:mm:ss"
  7. }
  8. }
  9. }

3. Delete Index

  1. DELETE index

4. The opening / closing Index

4.1 Opening index

  1. POST index/_open

Index closed 4.2

  1. POST index/_close

5. rebuild the index

  1. POST /_reindex
  2. {
  3. "source":{
  4. "index":"sourceIndexName",
  5. "query":{
  6.  
  7. },
  8. "sort":{
  9. "fieldName":"asc/desc"
  10. },
  11. "size":5000,
  12. "_source":[
  13. "fieldName1",
  14. "fieldName2",
  15. "fieldName3",
  16. ]
  17. },
  18. "dest":{
  19. "index":"destIndexName",
  20. "version_type":"internal(default)/external",
  21. "op_type":"create"
  22. }
  23. }

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

  1. POST /_aliases
  2. {
  3. "actions":[
  4. {
  5. "add":{
  6. "index":"indexName1",
  7. "alias":"aliasName"
  8. }
  9. },
  10. {
  11. "add":{
  12. "index":"indexName2",
  13. "alias":"aliasName"
  14. }
  15. }
  16. ]
  17. }

6.2 Delete alias

  1. POST /_aliases
  2. {
  3. "actions":[
  4. {
  5. "remove":{
  6. "index":"indexName",
  7. "alias":"aliasName"
  8. }
  9. }
  10. ]
  11. }

6.3 Renaming

  1. POST /_aliases
  2. {
  3. "actions":[
  4. {
  5. "remove":{
  6. "index":"indexName",
  7. "alias":"aliasName1"
  8. }
  9. },
  10. {
  11. "add":{
  12. "index":"indexName",
  13. "alias":"aliasName2"
  14. }
  15. }
  16. ]
  17. }

7. merge index

  1. POST index/_forcemerge?max_num_segments=1

8. narrow index

8.1 first index is set to read-only

  1. PUT source_index/_setting
  2. {
  3. "settings":{
  4. "index.routing.allocation.require._name":"node-1",
  5. "index.blocks.write":true
  6. }
  7. }

8.2 execution shrink

  1. POST source_index/_shrink/target_index
  2. {
  3. "settings":{
  4. "index.number_of_replicas":1,
  5. "index.number_of_shards":1,
  6. "index.codec":"best_compression"
  7. }
  8. }

Article from: java architecture

Published 277 original articles · won praise 65 · views 380 000 +

Guess you like

Origin blog.csdn.net/ailiandeziwei/article/details/104620460