Wednesday, 10 March 2021

How to use curl to GET query / search in elasticsearch?

You can use curl commands to search/query in elasticsearch just like in Kibana.

For example: 

you can get the count the number of documents in the cluster, you can use  GET _count endpoint.

Using curl:

curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/_count?pretty' -d '

{

"query" : {

"match_all" : {}

}

}'


Without the header, you might get 406 Not Acceptable exception like 

{

  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",

  "status" : 406

}



Respective kibana command(short-hand):


GET _count

{

  "query": {

    "match_all": {}

  }

}


No comments:

Post a Comment