【问题标题】:Weird output while placing elasticsearch curl command in shell script在 shell 脚本中放置 elasticsearch curl 命令时出现奇怪的输出
【发布时间】:2015-07-28 07:01:06
【问题描述】:

我有 elasticsearch curl 命令,我将它放在一个 shell 脚本中,如下所示:

#!/bin/bash


totalCount=`curl -XGET 'http://localhost:9200/_all/_count?pretty=true' -d '{
    "query" : {
        "bool" : {
                "must" : [
                        {
                        "match" : {
                                "type" : "mtaLogs"
                        }} ,
                        {
                        "filtered" : {
                        "filter" : {
                                "range" : {
                                        "@timestamp" : {
                                                "from" : "2015-07-27T00:00:01",
                                                "to" : "2015-07-27T23:59:59"
                                        }
                                }
                        }
                        }
                        }
                ]
        }
    }
}' | jq '.count'`

echo "Total mtaLogs count is $totalCount"

现在应该只显示输出为Total mtaLogs count is <some count>

但输出显示为

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    98    0    98    0   755   7572  58337 --:--:-- --:--:-- --:--:--     0
Total mtaLogs count is 39

为什么我在控制台上得到这个不必要的表格输出?

这里有什么帮助吗?

【问题讨论】:

    标签: bash shell curl elasticsearch


    【解决方案1】:

    您只需将-s-silent 开关添加到curl 命令,它将在没有详细表的情况下静默执行,即

    totalCount=`curl -s -XGET 'http://localhost:9200/_all/_count?pretty=true' -d '{
                      ^
                      |
                      |
                     HERE
    

    【讨论】:

    • 谢谢.. 它帮助了... :)
    猜你喜欢
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 2020-04-30
    • 2014-08-10
    • 2019-01-06
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    相关资源
    最近更新 更多