# Trying to get create snapshot working with elasticsearch javascript

**URL:** <https://discuss.elastic.co/t/trying-to-get-create-snapshot-working-with-elasticsearch-javascript/21225>\
**Category:** Elasticsearch\
**Created:** [December 12, 2014, 12:12am UTC](https://discuss.elastic.co/t/trying-to-get-create-snapshot-working-with-elasticsearch-javascript/21225 "2014-12-12T00:12:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [December 12, 2014, 12:12am UTC](https://discuss.elastic.co/t/trying-to-get-create-snapshot-working-with-elasticsearch-javascript/21225/1 "2014-12-12T00:12:28Z")

</div>

Hi,  
I am capable of creating a snapshot using sense or curl using the command:

PUT /\_snapshot/gridshore-repo/gridshore\_4  
{  
"indices": "gridshore\*"  
}

The problem is when I start doing something like this using the javascript  
library in angularjs.

es.snapshot.create({"repository":"gridshore-repo","snapshot":"gridshore\_4","indices":"gridshore\*"}).then(function(data)  
{  
callback();  
}, logErrors);

I get back errors like this:  
StatusCodeError: InvalidIndexNameException[[\_snapshot] Invalid index name  
[_snapshot], must not start with '_'] {message:  
"InvalidIndexNameException[[\_snapshot] Invalid index name [_snapshot], must  
not start with '_']", body: Object, status: 400, stack: (...)}

Does anyone have a clue how to fix this?

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/319912c1-711d-4d40-b5b6-8ba751091a9c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/319912c1-711d-4d40-b5b6-8ba751091a9c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [December 12, 2014, 9:40am UTC](https://discuss.elastic.co/t/trying-to-get-create-snapshot-working-with-elasticsearch-javascript/21225/2 "2014-12-12T09:40:38Z")

</div>

The problem was partly because I was doing it wrong. You need to provide  
additional parameters in a body element. And there is a bug in the snapshot  
creation, needs to be a PUT instead of a POST.

See issue:

> <https://github.com/elastic/elasticsearch-js/issues/170>
>
> To recreate this problem I have a node.js program. This is the code:
> 
> \`\`\`
> var el…asticsearch = require('elasticsearch');
> var client = new elasticsearch.Client({
> host: 'localhost:9200',
> log: 'trace',
> apiVersion: '1.4'
> });
> 
> var newRepo = {
> "repository":"gridshore-repo",
> "snapshot":"test-2",
> "body": {
> "indices":"gridshore-\*"
> }
> };
> 
> client.snapshot.create(newRepo).then(function(data) {
> console.log(data);
> });
> \`\`\`
> 
> And this is the output:
> 
> \`\`\`
> /usr/local/bin/node index.js
> Elasticsearch INFO: 2014-12-12T09:33:55Z
> Adding connection to http://localhost:9200/
> 
> Elasticsearch DEBUG: 2014-12-12T09:33:55Z
> starting request { method: 'POST',
> path: '/\_snapshot/gridshore-repo/test-2',
> body: { indices: 'gridshore-\*' },
> query: {} }
> 
> 
> Elasticsearch TRACE: 2014-12-12T09:33:55Z
> -\> POST http://localhost:9200/\_snapshot/gridshore-repo/test-2
> {
> "indices": "gridshore-\*"
> }
> \<- 400
> {
> "error": "InvalidIndexNameException\[\[\_snapshot\] Invalid index name \[\_snapshot\], must not start with \\u0027\_\\u0027\]",
> "status": 400
> }
> 
> Elasticsearch DEBUG: 2014-12-12T09:33:55Z
> Request complete
> 
> Possibly unhandled Error: InvalidIndexNameException\[\[\_snapshot\] Invalid index name \[\_snapshot\], must not start with '\_'\]
> at respond (/Users/jettrocoenradie/sources/temp/elastictry/node\_modules/elasticsearch/src/lib/transport.js:235:15)
> at checkRespForFailure (/Users/jettrocoenradie/sources/temp/elastictry/node\_modules/elasticsearch/src/lib/transport.js:203:7)
> at HttpConnector.\<anonymous\> (/Users/jettrocoenradie/sources/temp/elastictry/node\_modules/elasticsearch/src/lib/connectors/http.js:148:7)
> at IncomingMessage.bound (/Users/jettrocoenradie/sources/temp/elastictry/node\_modules/elasticsearch/node\_modules/lodash-node/modern/internals/baseBind.js:56:17)
> at IncomingMessage.emit (events.js:117:20)
> at \_stream\_readable.js:943:16
> at process.\_tickCallback (node.js:419:13)
> \`\`\`
> 
> Now the problem is easy to be solved by changing the apis 1\_4.js for example.
> api.snapshot.prototype.create
> 
> change the method from POST into PUT and you are done.
> 
> If you want me to I can create a pull request, but the changes are so trivial that a pull request might be more work.

Op vrijdag 12 december 2014 01:12:28 UTC+1 schreef Jettro Coenradie:

> Hi,  
> I am capable of creating a snapshot using sense or curl using the command:
> 
> PUT /\_snapshot/gridshore-repo/gridshore\_4  
> {  
> "indices": "gridshore\*"  
> }
> 
> The problem is when I start doing something like this using the javascript  
> library in angularjs.
> 
> es.snapshot.create({"repository":"gridshore-repo","snapshot":"gridshore\_4","indices":"gridshore\*"}).then(function(data)  
> {  
> callback();  
> }, logErrors);
> 
> I get back errors like this:  
> StatusCodeError: InvalidIndexNameException[[\_snapshot] Invalid index name  
> [_snapshot], must not start with '_'] {message:  
> "InvalidIndexNameException[[\_snapshot] Invalid index name [_snapshot], must  
> not start with '_']", body: Object, status: 400, stack: (...)}
> 
> Does anyone have a clue how to fix this?
> 
> 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/3a3614eb-6e07-41ce-82bd-2010ba2d25d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3a3614eb-6e07-41ce-82bd-2010ba2d25d4%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:43am UTC](https://discuss.elastic.co/t/trying-to-get-create-snapshot-working-with-elasticsearch-javascript/21225/3 "2017-07-06T00:43:56Z")

</div>


