# Export elasticsearch to a JSON file with Pig

**URL:** <https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [October 15, 2016, 10:53am UTC](https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099 "2016-10-15T10:53:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [October 15, 2016, 10:53am UTC](https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099/1 "2016-10-15T10:53:19Z")

</div>

Using the elasticsearch-hadoop library, I want to export elasticsearch index to JSON so I tried:

> A = LOAD 'events-sample/events'  
> USING org.elasticsearch.hadoop.pig.EsStorage(  
> 'es.nodes=es.analytics.blablacar.dev',  
> 'es.nodes.wan.only=true',  
> 'es.output.json=true',  
> 'es.query=?q=status:cancel');

> STORE A INTO '/user/admin/toto.json' USING JsonStorage();

But JsonStorage complains about a missing schema. So I tried many schema:

... AS (chararray), ... AS (line:map[chararray]) etc...

Then got the following Java exception from EsStorage.java:

> Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map  
> at org.elasticsearch.hadoop.pig.EsStorage.getNext(EsStorage.java:271)  
> at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigRecordReader.nextKeyValue(PigRecordReader.java:204)  
> at org.apache.tez.mapreduce.lib.MRReaderMapReduce.next(MRReaderMapReduce.java:116)  
> at org.apache.pig.backend.hadoop.executionengine.tez.plan.operator.POSimpleTezLoad.getNextTuple(POSimpleTezLoad.java:110)  
> at org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator.processInput(PhysicalOperator.java:307)  
> at org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach.getNextTuple(POForEach.java:252)  
> ... 17 more

I find the documentation is missing real examples to use elasticsearch on Hadoop for people with good ES skills but novice to Hadoop.

Thanks you,

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [October 17, 2016, 7:00pm UTC](https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099/2 "2016-10-17T19:00:19Z")

</div>

Thanks for posting this. I have also run into the same issues that you have described. I've opened an issue in the repository to track this: [https://github.com/elastic/elasticsearch-hadoop/issues/871](https://github.com/elastic/elasticsearch-hadoop/issues/871)

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [October 17, 2016, 7:17pm UTC](https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099/3 "2016-10-17T19:17:17Z")

</div>

Seriously, is there someone who are using elasticsearch for hadoop in production? I am very curious to see real project about this.

Many thanks for the issue.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:22pm UTC](https://discuss.elastic.co/t/export-elasticsearch-to-a-json-file-with-pig/63099/4 "2017-07-06T13:22:52Z")

</div>


