# \_reindex is not working when i pass index names as a variable

**URL:** <https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491>\
**Category:** Elasticsearch\
**Created:** [March 12, 2018, 7:34am UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491 "2018-03-12T07:34:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prabhakar\_talari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prabhakar_talari/32/46469_2.png) [@prabhakar\_talari](https://discuss.elastic.co/u/prabhakar_talari)\
**Post date:** [March 12, 2018, 7:34am UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491/1 "2018-03-12T07:34:28Z")

</div>

Hi All,

\_reindex is not working when i pass index names as a variable.

###Create New index for Backup

index\_name="test"  
create\_index="test-bkp"

curl -s -u username:password -XPUT "[http://localhost:9200/$create\_index](http://localhost:9200/%24create_index)"

###Copy Existing Index

curl -s -u username:password -XPOST '[http://localhost:9200/\_reindex?pretty](http://localhost:9200/_reindex?pretty)' -H 'Content-Type: application/json' -d'  
{  
"source": {  
"index": "$index\_name"  
},  
"dest": {  
"index": "$create\_index"  
}  
}  
'

=== Working if i speicfy index names like below

###Create New index for Backup

index\_name="test"  
create\_index="test-bkp"

curl -s -u username:password -XPUT "[http://localhost:9200/$create\_index](http://localhost:9200/%24create_index)"

###Copy Existing Index

curl -s -u username:password -XPOST '[http://localhost:9200/\_reindex?pretty](http://localhost:9200/_reindex?pretty)' -H 'Content-Type: application/json' -d'  
{  
"source": {  
"index": "test"  
},  
"dest": {  
"index": "test-bkp"  
}  
}  
'

Could any one suggest as i am trying to automate this with shell script

Thanks

---

<div class="post-metadata">

**Author:** ![Julien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julien/32/19688_2.png) [@Julien](https://discuss.elastic.co/u/Julien)\
**Post date:** [March 12, 2018, 10:34pm UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491/2 "2018-03-12T22:34:29Z")

</div>

This link has same question about the fact variables will not be extended when placed between single quotes : [https://stackoverflow.com/questions/13341955/how-to-pass-a-variable-in-a-curl-command-in-shell-scripting](https://stackoverflow.com/questions/13341955/how-to-pass-a-variable-in-a-curl-command-in-shell-scripting)

---

<div class="post-metadata">

**Author:** ![prabhakar\_talari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prabhakar_talari/32/46469_2.png) [@prabhakar\_talari](https://discuss.elastic.co/u/prabhakar_talari)\
**Post date:** [March 13, 2018, 12:52pm UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491/3 "2018-03-13T12:52:34Z")

</div>

Hi Julien,

Thanks or the response.

But my scenario is different, As per the link with in curl command we can able to pass the fact variables.

Here i am trying to pass the fact variables in fields but it is not accepting

---

<div class="post-metadata">

**Author:** ![prabhakar\_talari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prabhakar_talari/32/46469_2.png) [@prabhakar\_talari](https://discuss.elastic.co/u/prabhakar_talari)\
**Post date:** [March 13, 2018, 1:05pm UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491/4 "2018-03-13T13:05:23Z")

</div>

Hi Julien,

Sorry, i got.

It's working now.

Thank you so much 🙂

---

<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:** [April 10, 2018, 1:06pm UTC](https://discuss.elastic.co/t/reindex-is-not-working-when-i-pass-index-names-as-a-variable/123491/5 "2018-04-10T13:06:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
