# Is it possible to access a variable inside the include area?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-access-a-variable-inside-the-include-area/20383>\
**Category:** Elasticsearch\
**Created:** [October 22, 2014, 4:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-access-a-variable-inside-the-include-area/20383 "2014-10-22T16:05:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [October 22, 2014, 4:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-access-a-variable-inside-the-include-area/20383/1 "2014-10-22T16:05:48Z")

</div>

Hi everyone,

How can i use a variable inside include area? is it possible? how?  
I'm using groovy script in my query and it looks like:

GET /my\_index/my\_type/\_search  
{  
"\_source": false,  
"query": {  
"bool": {  
...  
}  
},  
"aggs": {  
"group": {  
"nested": {  
"path": "my\_path"  
},  
"aggs": {  
"path\_id": {  
"terms": {  
"field": "my\_path.id",  
"lang": "groovy",  
"script": "def _myVar_ = (\_value.split('\\.').findIndexOf {  
it == '3238175' }+1); _myVar_ + '/' + \_value; ",  
"include": "_myVar_/.\*",  
"size": 0  
}  
}  
}  
}  
}  
}

The variable "myVar" is working inside script. Is it possible to use it  
inside include?  
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/972dc840-28eb-44c7-be9b-4bb868e660d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/972dc840-28eb-44c7-be9b-4bb868e660d8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [October 22, 2014, 4:31pm UTC](https://discuss.elastic.co/t/is-it-possible-to-access-a-variable-inside-the-include-area/20383/2 "2014-10-22T16:31:12Z")

</div>

I have solved with RegEx

GET /my\_index/my\_type/\_search  
{  
"\_source": false,  
"query": {  
"bool": {  
...  
}  
},  
"aggs": {  
"group": {  
"nested": {  
"path": "my\_path"  
},  
"aggs": {  
"path\_id": {  
"terms": {  
"field": "my\_path.id",  
"lang": "groovy",  
"script": "def _myVar_ = (\_value.split('\\.').findIndexOf { it  
== '3238175' }+1); _myVar_ + '/' + \_value; ",  
"include": "_[1-4]_/.\*",  
"size": 0  
}  
}  
}  
}  
}  
}

--  
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/d943e0e8-066c-4db0-89e0-75d8fbaf34e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d943e0e8-066c-4db0-89e0-75d8fbaf34e5%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:54am UTC](https://discuss.elastic.co/t/is-it-possible-to-access-a-variable-inside-the-include-area/20383/3 "2017-07-06T00:54:22Z")

</div>

Closed on July 6, 2017, 12:54am UTC


