# Getting the index name of documents in Spark

**URL:** <https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [June 13, 2016, 9:05am UTC](https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580 "2016-06-13T09:05:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirilyuro](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@kirilyuro](https://discuss.elastic.co/u/kirilyuro)\
**Post date:** [June 13, 2016, 9:05am UTC](https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580/1 "2016-06-13T09:05:53Z")

</div>

ES-Spark's esRDD method returns the raw document (\_source, in ElasticSearch terms) and the document's id (\_id in ES), but I also need additional information regarding the returned documents, such as the index name and type each document comes from.

I am querying multiple indices, i.e. my call to esRDD looks like this:  
sparkContext.esRDD("index\*/entities", query)  
and the actual indices are "index1", "index2", etc. So, I want to know which specific index each of the documents in the resulting RDD came from.

Can this be done?

Thanks

---

<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:** [June 13, 2016, 2:45pm UTC](https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580/2 "2016-06-13T14:45:26Z")

</div>

Hello!

Please take a look at this section of the documentation : [https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html#\_metadata\_when\_reading\_from\_elasticsearch](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html#_metadata_when_reading_from_elasticsearch)

That should get you to where you want to go.

---

<div class="post-metadata">

**Author:** ![kirilyuro](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@kirilyuro](https://discuss.elastic.co/u/kirilyuro)\
**Post date:** [June 14, 2016, 4:07pm UTC](https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580/3 "2016-06-14T16:07:16Z")

</div>

Yeah, did the trick. Thanks!

---

<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:24pm UTC](https://discuss.elastic.co/t/getting-the-index-name-of-documents-in-spark/52580/4 "2017-07-06T13:24:21Z")

</div>


