--- title: Elasticsearch 確認資料比數正確 tags: Elasticsearch description: View the slide with "Slide Mode". --- # Elasticsearch 確認資料比數正確 <!-- Put the link to this slide here so people can follow --> ## 作法:透過定期(每天)檢查 Elasticaearch 以及 log 檔案的筆數是否一致 - 全部放在同一個 index - 每天以一個 document存放 ## 程式碼流程 1. 先掃過一遍有哪些專案 2. 建立一個 dictionary,存放專案及對應的 log 筆數 3. 對 Elasticsearch 昨天的資料,不分專案算總數 4. 總數相同的話,對 ES 寫入`{"status": "success"}` 5. 總數不同的話,分專案query,對 ES 寫入 `{"status": "fail", "project": ["p1", "p2"]}`