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

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


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"


You should URL encode your query in the first case:

http://localhost:9200/app/users/_search?source=%7b%22query%22%3a+%7b%22term%22%3a+%7b%22email%22%3a%22foo%40gmail.com%22%7d%7d%7d


The above answers are not compatible with the Elastic search Version 6.0 and above.The ES introduced Strict Content type check from the version 6.0.The link explains it:https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests.For curl, need to add -H'Content-Type: application/json' to the command line of any request that has a JSON body