ElasticSearch POST with json search body vs GET with json in url

前端 未结 2 1958
孤城傲影
孤城傲影 2021-02-07 10:21

According to the ES documentation, those 2 search request should get the same results:

GET

http://localhost:9200/app/users/_search?source={\"query\": {         


        
2条回答
  •  忘了有多久
    2021-02-07 11:08

    source is not a valid query string argument according to URI Search

    Elasticsearch allows three ways to perform a search request...

    GET with request body:

    curl -XGET "http://localhost:9200/app/users/_search" -d '{
      "query": {
        "term": {
          "email": "foo@gmail.com"
        }
      }
    }'
    

    POST with request body:

    Since not all clients support GET with body, POST is allowed as well.

    curl -XPOST "http://localhost:9200/app/users/_search" -d '{
      "query": {
        "term": {
          "email": "foo@gmail.com"
        }
      }
    }'
    

    GET without request body:

    curl -XGET "http://localhost:9200/app/users/_search?q=email:foo@gmail.com"
    

    or (if you want to manually URL encode your query string)

    curl -XGET "http://localhost:9200/app/users/_search?q=email%3Afoo%40gmail.com"
    

提交回复
热议问题