簡體   English   中英

如何使用 bash 腳本處理彈性搜索 resource_already_exists_exception

[英]How to handle elastic search resource_already_exists_exception using bash script

我對 Elastic 和 bash 腳本還很陌生。 誰能幫我解決以下問題-我如何跳過使用 bash 創建已經存在的彈性索引

首先,我在 bash 腳本中創建映射 -

#!/bin/bash

curl --user uid:password -X PUT **"https:localhost/newindex"** -H 'Content-Type: application/json' -d'{  "mappings": { "properties": {.....}}}}'

#然后我將數據添加到它

curl --user uid:password -X POST **"https:localhost/newindex"** -H 'Content-Type: application/json' -d'{"date":"data..."...... }'

如果我第一次運行它,它會起作用,但是當我第二次運行時,它會給我一個錯誤“resource_already_exists_exception” ,我該如何使用 bash 腳本處理這個問題

您可以使用 --fail 標志:

-f, --fail (HTTP) 在服務器錯誤時靜默失敗(根本沒有 output)。 這主要是為了更好地使腳本等更好地處理失敗的嘗試。 在正常情況下,當 HTTP 服務器無法傳遞文檔時,它會返回一個 HTML 文檔說明(通常還描述原因等)。 該標志將阻止 curl 輸出它並返回錯誤 22。

如果命令成功,退出代碼將為零,因此您可以檢查:

curl --fail --user uid:password -X POST "https:localhost/newindex" -H 'Content- 
Type: application/json' -d'{"date":"data..."...... }'

if [ 0 -eq $? ]; then … fi;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM