Some settings you need to define when the index is created and can never change (like number of shards). The node library has no support for many of the options the REST API supports when creating indexes.
I would expect params to also accept mappings, settings, warmers, and aliases. The following would be a valid params argument to client.indices.create(payload, callback)
var payload = {
"index": "events-2015-11",
"settings": {
"number_of_shards": 100,
"number_of_replicas": 1
},
"mappings": {
"event": {
"properties": {
"ip": { "type": "string" },
"guid": { "type": "string" },
"userId": { "type": "string" },
"key": { "type": "string" },
"value": { "type": "string" },
"type": { "type": "string" },
"campaign": { "type": "string" },
"source": { "type": "string" },
"medium": { "type": "string" },
"quantity": { "type": "double" },
"data": { "type": "object" },
"createdAt": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
},
"warmers" : {},
"aliases" : {"events": {}}
}
The payload variable you listed isn't actually the payload sent to elasticsearch. As described in the api conventions document the payload/body is specified as the body: parameter to the client.
So I think what you meant to send was something like this:
var payload = {
"settings": {
"number_of_shards": 100,
"number_of_replicas": 1
},
"mappings": {
"event": {
"properties": {
"ip": { "type": "string" },
"guid": { "type": "string" },
"userId": { "type": "string" },
"key": { "type": "string" },
"value": { "type": "string" },
"type": { "type": "string" },
"campaign": { "type": "string" },
"source": { "type": "string" },
"medium": { "type": "string" },
"quantity": { "type": "double" },
"data": { "type": "object" },
"createdAt": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
},
"warmers" : {},
"aliases" : {"events": {}}
};
var params = {
"index": "events-2015-11",
"body": payload
};
client.indices.create(params, callback)
Most helpful comment
The
payloadvariable you listed isn't actually the payload sent to elasticsearch. As described in the api conventions document the payload/body is specified as thebody:parameter to the client.So I think what you meant to send was something like this: