0

Can anyone help me to convert the following into java equivalent?

curl -XGET 'localhost:9200/indexname/status/_search?pretty=1&size=10000' -d '{"_source": {"include": [ "ID", "Name" ]}}'

I tried to use this:

ProcessBuilder pb = new ProcessBuilder("curl","-g","-H Content-Type: application/json", "-H Accept: application/json", "-XGET","http://localhost:9200/indexname/status/_search?pretty=1&size=10000","-d '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}'");

On running the java code, it return a Parse failure exception. Any advice? Thanks.

Sweet
  • 187
  • 3
  • 15
  • running a command in Java (e.g. curl) is not portable (e.g. it won't run if not installed and added to path). Why don't you use the high level methods for that: http://stackoverflow.com/a/2587000/819651 – Luís Soares Mar 29 '16 at 07:08
  • You can use jest client of elastic search as an alternate method – Sachin Mar 29 '16 at 09:56

1 Answers1

0

I found this which works for me.

https://github.com/eeichinger/jcurl

jCurl is a curl-inspired, java-based HTTP command line client. It can be distributed as a single executable JAR

tk421
  • 5,775
  • 6
  • 23
  • 34