求适用于PowerShell的ElasticSearch磁盘阈值配置命令
Solution: Convert Elasticsearch Curl Command to Working PowerShell Invoke-RestMethod
I get it—dealing with Elasticsearch disk threshold alerts spamming your logs is annoying enough, and then hitting a wall converting the curl command to PowerShell on Windows just adds to the frustration. Let’s cut straight to the working command you need:
Invoke-RestMethod -Method Put -Uri "http://localhost:9200/_cluster/settings" -ContentType "application/json" -Body '{ "persistent" : { "cluster.routing.allocation.disk.threshold_enabled" : "false" } }'
Why your previous attempts might have failed:
- Missing the PUT method: By default,
Invoke-RestMethoduses GET if you don’t specify-Method Put, which won’t modify cluster settings. - JSON formatting issues: PowerShell is picky about string quoting. Using single quotes around the entire JSON body avoids conflicts with the double quotes inside the JSON structure.
- Forgotten Content-Type header: Elasticsearch requires the
Content-Type: application/jsonheader to parse the request body correctly—omitting this will lead to errors.
Verify the setting took effect:
To confirm the disk threshold is disabled, run this command to check the current cluster settings:
Invoke-RestMethod -Uri "http://localhost:9200/_cluster/settings?include_defaults=false"
Look for the persistent section in the output—you should see "cluster.routing.allocation.disk.threshold_enabled": "false" listed.
内容的提问来源于stack exchange,提问作者user7951690
相关产品推荐
相关产品推荐

