Running Elasticsearch Search Commands in Python and Bash Using Curl

In this post, I will discuss about running Elasticsearch commands in Python using Curl

  • How to do Search in Python using Curl

import json
import subprocess
index = 'myindex'
package = 'mypackage'

cmd='curl -X GET "%s:9200/%s/_search?pretty=true" -H "Content-Type: application/json" -d \'{"query": {"match_phrase" : {"package" : %s}}}\''%('http://localhost' ,index,package)

process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

stdout, stderr = process.communicate()


  • How to run Elasticearch Commands in Bash using Curl

curl -XGET 'http://localhost:9200/myindex/doctype/_search?pretty=true' -H "Content-Type: application/json" -d '{ \
"query": { \
"match_phrase" : { \
"package" : "mypackage" \
  } \  

command line history