ElasticSearch刪除所有文檔數據以及更改索引類型

ElasticSearch版本6.4

刪除所有文檔

post提交
http:ip:port/index_name/_delete_by_query

http://192.168.2.141:9200/mop_monitor_social_graph/_delete_by_query

更改索引字段類型

基於es6.4 僅適用與開發測試階段

  • 獲取原始索引類型映射結構
http://192.168.1.7:9200/mop_monitor_page_session/_mapping
  • put新的索引結構
http://192.168.2.141:9200/mop_monitor_page_session_new

{
        "mappings": {
            "mop_monitor_page_session": {
                "properties": {
                    "channelId": {
                        "type": "integer"
                    },
                    "city": {
                        "type": "keyword"
                    },
                    "dateTime": {
                        "type": "date"
                    },
                    "deviceType": {
                        "type": "integer"
                    },
                    "duration": {
                        "type": "long"
                    },
                    "endTime": {
                        "type": "date"
                    },
                    "firstVisit": {
                        "type": "boolean"
                    },
                    "ip": {
                        "type": "ip"
                    },
                    "pageId": {
                        "type": "integer"
                    },
                    "pageUrl": {
                        "type": "text"
                    },
                    "pageUrlHash": {
                        "type": "keyword"
                    },
                    "projectId": {
                        "type": "integer"
                    },
                    "province": {
                        "type": "keyword"
                    },
                    "sessionId": {
                        "type": "keyword"
                    },
                    "url": {
                        "type": "keyword"
                    },
                    "uuid": {
                        "type": "keyword"
                    },
                    "visitorType": {
                        "type": "integer"
                    }
                }
            }
        }
    }
  • 將原始索引中的數據遷移到新索引上
POST : http://192.168.1.7:9200/_reindex
{
  "source": {
    "index": "mop_monitor_page_session"
  },
  "dest": {
    "index": "mop_monitor_page_session_new"
  }
}
  • 刪除舊的索引結構
DELETE http://192.168.2.141:9200/mop_monitor_page_session
  • 對舊索引重新put新的映射結構
PUT http://192.168.2.141:9200/mop_monitor_page_session
{
        "mappings": {
            "mop_monitor_page_session": {
                "properties": {
                    "channelId": {
                        "type": "integer"
                    },
                    "city": {
                        "type": "keyword"
                    },
                    "dateTime": {
                        "type": "date"
                    },
                    "deviceType": {
                        "type": "integer"
                    },
                    "duration": {
                        "type": "long"
                    },
                    "endTime": {
                        "type": "date"
                    },
                    "firstVisit": {
                        "type": "boolean"
                    },
                    "ip": {
                        "type": "ip"
                    },
                    "pageId": {
                        "type": "integer"
                    },
                    "pageUrl": {
                        "type": "text"
                    },
                    "pageUrlHash": {
                        "type": "keyword"
                    },
                    "projectId": {
                        "type": "integer"
                    },
                    "province": {
                        "type": "keyword"
                    },
                    "sessionId": {
                        "type": "keyword"
                    },
                    "url": {
                        "type": "keyword"
                    },
                    "uuid": {
                        "type": "keyword"
                    },
                    "visitorType": {
                        "type": "integer"
                    }
                }
            }
        }
    }

  • 將數據從新建的索引山遷移到重建的舊索引上
POST http://192.168.1.7:9200/_reindex
{
  "source": {
    "index": "mop_monitor_page_session_new"
  },
  "dest": {
    "index": "mop_monitor_page_session"
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章