# \[ES 0.90.13\] How to get the index name in a facet script?

**URL:** https://discuss.elastic.co/t/es-0-90-13-how-to-get-the-index-name-in-a-facet-script/20212
**Category:** Elasticsearch
**Created:** [October 13, 2014, 9:34am UTC](https://discuss.elastic.co/t/es-0-90-13-how-to-get-the-index-name-in-a-facet-script/20212 "2014-10-13T09:34:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [October 13, 2014, 9:34am UTC](https://discuss.elastic.co/t/es-0-90-13-how-to-get-the-index-name-in-a-facet-script/20212/1 "2014-10-13T09:34:12Z")

</div>

Hi everybody,

I cannot figure out how to get the index name in a facet script with ES  
0.90.13.  
I tried the following syntax but neither of them didn't work:

with doc:

- {\*
- "size": 0, \*
- "facets" : {\*
- 

```
 "indices" : { "terms" : {"script" : "doc['_index'].value"} }*

```

- }\*
- }\*

with \_source:

- {\*
- "size": 0, \*
- "facets" : {\*
- 

```
 "indices" : { "terms" : {"script" : "_source['_index']"} }*

```

- }\*
- }\*

Both of 2 syntax above return:  
"facets": {  
"indices": {  
"\_type": "terms",  
"missing": 36289,  
"total": 0,  
"other": 0,  
"terms": []  
}  
}

Should I use my own field instead of the built-in "\_index" ?

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/32c05c7b-9e76-43e5-b0e3-05d663219cd7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/32c05c7b-9e76-43e5-b0e3-05d663219cd7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Mehrez\_Marouani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehrez_marouani/32/1218_2.png) [@Mehrez\_Marouani](https://discuss.elastic.co/u/Mehrez_Marouani)
#### Post date: [October 13, 2014, 9:45am UTC](https://discuss.elastic.co/t/es-0-90-13-how-to-get-the-index-name-in-a-facet-script/20212/2 "2014-10-13T09:45:59Z")

</div>

I finally figured out that I forgot to enable the "\_index" field in my  
mapping as it's disabled by default:

"\_index": {  
"enabled": true  
}

On Monday, 13 October 2014 11:34:12 UTC+2, Mehrez Marouani wrote:

> Hi everybody,
> 
> I cannot figure out how to get the index name in a facet script with ES  
> 0.90.13.  
> I tried the following syntax but neither of them didn't work:
> 
> with doc:
> 
> - {\*
> - "size": 0, \*
> - "facets" : {\*
> - 
> 
> ```
> "indices" : { "terms" : {"script" : "doc['_index'].value"} }*
> 
> ```
> 
> - }\*
> - }\*
> 
> with \_source:
> 
> - {\*
> - "size": 0, \*
> - "facets" : {\*
> - 
> 
> ```
> "indices" : { "terms" : {"script" : "_source['_index']"} }*
> 
> ```
> 
> - }\*
> - }\*
> 
> Both of 2 syntax above return:  
> "facets": {  
> "indices": {  
> "\_type": "terms",  
> "missing": 36289,  
> "total": 0,  
> "other": 0,  
> "terms":   
> }  
> }
> 
> Should I use my own field instead of the built-in "\_index" ?
> 
> Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0560bfeb-1250-465d-ba87-57a351cab720%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0560bfeb-1250-465d-ba87-57a351cab720%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:56am UTC](https://discuss.elastic.co/t/es-0-90-13-how-to-get-the-index-name-in-a-facet-script/20212/3 "2017-07-06T00:56:37Z")

</div>


