# API calls from within Plugin

**URL:** <https://discuss.elastic.co/t/api-calls-from-within-plugin/142527>\
**Category:** Elasticsearch\
**Created:** [August 1, 2018, 9:49am UTC](https://discuss.elastic.co/t/api-calls-from-within-plugin/142527 "2018-08-01T09:49:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin-huber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin-huber/32/33946_2.png) [@martin-huber](https://discuss.elastic.co/u/martin-huber)\
**Post date:** [August 1, 2018, 9:49am UTC](https://discuss.elastic.co/t/api-calls-from-within-plugin/142527/1 "2018-08-01T09:49:25Z")

</div>

Hi all,

we want to write a Plugin that needs to be able to perform certain operations, that wouldn't be a problem over the API. But I have the feeling, that it is not a good idea, to do a REST call from within a Plugin, and that there should be a better way to access certain functionality?  
Concretely:

- check, if the local node is the current Master
- close an index  
Ideally also:
- check, how long an Index is open
- get the Index that is open for the longest time

Are there components that I could inject into the Plugin to perform these operations and get this information ?

Thanks !

Martin

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 2, 2018, 9:37am UTC](https://discuss.elastic.co/t/api-calls-from-within-plugin/142527/2 "2018-08-02T09:37:14Z")

</div>

the `ClusterService` and the `Client` handed over in `Plugin.createComponents` will help you.

`ClusterService.localNode().isMasterNode()`. The cluster service also allows you to access the cluster state to get all the index metadata. Not sure if `open` is something you can check for, but the creation date might help.

---

<div class="post-metadata">

**Author:** ![martin-huber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin-huber/32/33946_2.png) [@martin-huber](https://discuss.elastic.co/u/martin-huber)\
**Post date:** [August 2, 2018, 9:54am UTC](https://discuss.elastic.co/t/api-calls-from-within-plugin/142527/3 "2018-08-02T09:54:42Z")

</div>

Cool! Thanks a lot! I will look into this !

---

<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:** [August 30, 2018, 10:04am UTC](https://discuss.elastic.co/t/api-calls-from-within-plugin/142527/4 "2018-08-30T10:04:32Z")

</div>

Closed on August 30, 2018, 10:04am UTC

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