gpt4 book ai didi

elasticsearch - curl如何使用数据有效载荷执行获取请求?

转载 作者:行者123 更新时间:2023-12-02 22:54:27 25 4
gpt4 key购买 nike

ElasticSearch的入门资料包括以下示例curl请求:

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"query_string" : {
"query" : "(new york city) OR (big apple)",
"default_field" : "content"
}
}
}
'

该请求有两个我认为不兼容的参数:
  • -X GET,它指定请求为GET
  • -d [...],它指定请求具有数据有效负载。

  • 我认为只能在 PUTPOST请求中指定数据有效负载,因为 GET请求没有任何数据有效负载的概念。这是有效的 curl命令吗?到底是做什么的?

    最佳答案

    curl请求上方是一个有效的请求,实际上,如果您有索引和数据,则可以检查命令的输出。

    我在系统和ES索引中进行了尝试,并给出了正确的响应。

    curl -v -X GET "localhost:9500/querytime/_search?pretty" -H 'Content-Type: application/json' -d'
    {
    "query": {
    "query_string" : {
    "query" : "(avengers) OR (big apple)",
    "default_field" : "movie_name"
    }
    }
    }'
    * Trying ::1...
    * TCP_NODELAY set
    * Connected to localhost (::1) port 9500 (#0)
    > GET /querytime/_search?pretty HTTP/1.1
    > Host: localhost:9500
    > User-Agent: curl/7.64.1
    > Accept: */*
    > Content-Type: application/json
    > Content-Length: 156
    >
    * upload completely sent off: 156 out of 156 bytes
    < HTTP/1.1 200 OK
    < content-type: application/json; charset=UTF-8
    < content-length: 905
    <
    {
    "took" : 4,
    "timed_out" : false,
    "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
    },
    "hits" : {
    "total" : {
    "value" : 3,
    "relation" : "eq"
    },
    "max_score" : 0.14874382,
    "hits" : [
    {
    "_index" : "querytime",
    "_type" : "_doc",
    "_id" : "1",
    "_score" : 0.14874382,
    "_source" : {
    "movie_name" : "Avengers: Infinity War"
    }
    }
    ]
    }
    }

    如curl命令的官方手册中所述,如果您使用的是基于 *nix的系统,则可以在 curl手册中进行以下搜索。

    -G, --get When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator



    this SO回答中所述,它还取决于Web服务器来解析GET请求中的主体。

    关于elasticsearch - curl如何使用数据有效载荷执行获取请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60254541/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com