Rahul Sharma
Rahul Sharma

Reputation: 63

Write elasticsearch data in json file

I have 3 node elasticsearch cluster and I put data in index name pp_index in json format. I want to read that data and write in json file.

I can read data from below command but how can I write that data in json file

   curl -H 'Content-Type: application/json' -X GET http://localhost:9200/pp_index/_search?pretty

Upvotes: 1

Views: 2772

Answers (1)

Sagar Patel
Sagar Patel

Reputation: 5486

You can use curl -o parameter to write output to the file like below:

curl -H 'Content-Type: application/json' -X GET http://localhost:9200/pp_index/_search?pretty -o myfile.json

But above search API will return only top 10 document from your index as you are not passing size param. If you need more data you can set size param value and it support max 10000.

http://localhost:9200/pp_index/_search?size=10000

I will suggest to use Java or Python elasticsearch client as you can get all the data from index and export it using client.

Upvotes: 2

Related Questions