一般日期格式的可能需要重新设置。

原始索引

  1. PUT /people_v1
  2. {
  3. "settings": {
  4. "number_of_shards": 1,
  5. "number_of_replicas": 0
  6. }
  7. }
  8. # 设置别名
  9. PUT /people_v1/_alias/people
  10. POST people_v1/_mapping/doc
  11. {
  12. "dynamic": "strict",
  13. "properties": {
  14. "birth": {
  15. "type": "text"
  16. }
  17. }
  18. }
  19. POST /people_v1/doc
  20. {
  21. "birth": "2019-09-09"
  22. }

替换索引

  1. PUT /people_v2
  2. {
  3. "settings": {
  4. "number_of_shards": 1,
  5. "number_of_replicas": 0
  6. }
  7. }
  8. POST people_v2/_mapping/doc
  9. {
  10. "dynamic": "strict",
  11. "properties": {
  12. "birth": {
  13. "type": "date",
  14. "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
  15. }
  16. }
  17. }
  18. POST _reindex
  19. {
  20. "source": {
  21. "index": "people_v1"
  22. },
  23. "dest": {
  24. "index": "people_v2"
  25. }
  26. }
  27. # 没问题的话修改别名,实现无缝切换索引
  28. POST /_aliases
  29. {
  30. "actions": [
  31. {
  32. "remove": {
  33. "index": "people_v1",
  34. "alias": "people"
  35. }
  36. },
  37. {
  38. "add": {
  39. "index": "people_v2",
  40. "alias": "people"
  41. }
  42. }
  43. ]
  44. }
  45. # 验证是否成功,查看别名对应的索引
  46. GET /*/_alias/people