# Plugin Development - Saving Updates

**URL:** <https://discuss.elastic.co/t/plugin-development-saving-updates/74705>\
**Category:** Kibana\
**Created:** [February 10, 2017, 7:38pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705 "2017-02-10T19:38:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kikketer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikketer/32/13813_2.png) [@Kikketer](https://discuss.elastic.co/u/Kikketer)\
**Post date:** [February 10, 2017, 7:38pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/1 "2017-02-10T19:38:32Z")

</div>

**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:

```javascript
  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 😱

---

<div class="post-metadata">

**Author:** ![BigFunger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigfunger/32/7323_2.png) [@BigFunger](https://discuss.elastic.co/u/BigFunger)\
**Post date:** [February 10, 2017, 7:52pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/2 "2017-02-10T19:52:44Z")

</div>

You should be able to use the 'index' action.

```auto
callWithRequest(request, 'index', {
  index: 'my-index',
  type: 'documents',
  id: 'document_12345',
  body: {
    fieldA: 'something',
    fieldB: 'awesome'
  }
});

```

let me know if that works for you.

---

<div class="post-metadata">

**Author:** ![Kikketer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikketer/32/13813_2.png) [@Kikketer](https://discuss.elastic.co/u/Kikketer)\
**Post date:** [February 10, 2017, 7:53pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/3 "2017-02-10T19:53:43Z")

</div>

Fantastic thanks, I'll give that a spin. Are the action types that `callWithRequest` can do documented somewhere (even if it's in the kibana source)?

Also the watcher API has 3 levels. What would it look like for that?

```auto
index: '_xpack',
type: 'watchers',
third: 'watcher',
id: 'fancy-watcher'

```

---

<div class="post-metadata">

**Author:** ![BigFunger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigfunger/32/7323_2.png) [@BigFunger](https://discuss.elastic.co/u/BigFunger)\
**Post date:** [February 10, 2017, 8:00pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/4 "2017-02-10T20:00:14Z")

</div>

try this:

```auto
callWithRequest(request, 'transport.request', {
  path: '/_xpack/watcher/watch/fancy-watcher',
  method: 'POST',
  body: { ... }
});

```

---

<div class="post-metadata">

**Author:** ![Kikketer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikketer/32/13813_2.png) [@Kikketer](https://discuss.elastic.co/u/Kikketer)\
**Post date:** [February 10, 2017, 8:01pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/5 "2017-02-10T20:01:04Z")

</div>

Delicious, thanks. I'm getting more powerful every day 🙂

Thanks for the quick reply.

---

<div class="post-metadata">

**Author:** ![BigFunger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigfunger/32/7323_2.png) [@BigFunger](https://discuss.elastic.co/u/BigFunger)\
**Post date:** [February 10, 2017, 8:01pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/6 "2017-02-10T20:01:55Z")

</div>

You're welcome!

---

<div class="post-metadata">

**Author:** ![BigFunger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigfunger/32/7323_2.png) [@BigFunger](https://discuss.elastic.co/u/BigFunger)\
**Post date:** [February 10, 2017, 8:06pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/7 "2017-02-10T20:06:04Z")

</div>

AFAIK, the callWithRequest is a wrapper around the elasticsearch.js module. Documentation can be found [here](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html)

---

<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:** [March 10, 2017, 8:06pm UTC](https://discuss.elastic.co/t/plugin-development-saving-updates/74705/8 "2017-03-10T20:06:19Z")

</div>

Closed on March 10, 2017, 8:06pm UTC

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