How do I save things to Elastic from the server side of a plugin?
I have several use cases coming up where I will either need to insert a document into an index or use the Watcher API to save a watcher.
I may be crazy but I can't find much documentation around this type of thing. Right now I'm stumbling around and generally successful getting data by using the callWithRequest
that I get out of server.plugins.elasticsearch.getCluster('data')
.
I'm wondering is there some way of either using callWithRequest
to save a new document or is there something else completely that is used to save data. The CURL and other documentation for inserting documents makes sense if you are on the client side, but I'm on the server side (kibana) attempting to push data into Elastic.
Here's some psudo code of what I'm attempting:
let {callWithRequest} = server.plugins.elasticsearch.getCluster('data');
let document = {
index: 'my-index',
body: {
fieldA: 'something',
fieldB: 'awesome'
}
};
callWithRequest(request, 'insert?', document).then((result) => reply('All good'));
And getting the document to insert is fine. Then what about the Watcher API, where .watches
is read only and I have to use the defined methods: _xpack/watcher/watches/...
Please help