# Accessing to different index from the contoroller in kibana

**URL:** <https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666>\
**Category:** Kibana\
**Created:** [August 10, 2016, 8:03am UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666 "2016-08-10T08:03:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 10, 2016, 8:03am UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666/1 "2016-08-10T08:03:50Z")

</div>

Hi!

I am now writing code for custom plugin in kibana.

What I want to do is, access to different index from the current scope.

I have a controller for visualization app accessing to **index1** now as below .

```
  module.controller('PluginController', function ($scope, Private) {
      $scope.$watch('esResponse', function (resp) {
        if (resp) {
         var bucketId = $scope.vis.aggs.bySchemaName['bucket'][0].id;

         var buckets = resp.aggregations[bucketId].buckets;

         $scope.bucket = buckets.map(function(bucket)) {
           return {
             label: bucket.key
           };
         };
        }
      });
    });

```

But I want to access to index **test2** too in my custom logic.  
Is this possible in visualization app?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [August 11, 2016, 3:02am UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666/2 "2016-08-11T03:02:19Z")

</div>

It's not very clear what your goals are. Seems that you access `index1` because that's the selected index pattern for your visualization, but is the `index2` name supposed to be hardcoded in your controller for a follow-up query? Is the goal going to be to join data from the initial response with data from `index2`?

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 12, 2016, 12:31am UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666/3 "2016-08-12T00:31:01Z")

</div>

Hi @tsullivan

Sorry that I didnt make things clear.

What I want to do is to access index1 and index2 regardless of selected index in vidualization.

I assume this is possible using javascript client of elasticsearch.

[https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html)

Am I correct?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [August 31, 2016, 6:37pm UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666/4 "2016-08-31T18:37:03Z")

</div>

> Am I correct?

Yes, you should be able to get the Elasticsearch client by creating a module that has the `es` dependency, which is the Elasticsearch client. An example from Kibana: [https://github.com/elastic/kibana/blob/v4.5.4/src/ui/public/courier/fetch/\_call\_client.js#L2](https://github.com/elastic/kibana/blob/v4.5.4/src/ui/public/courier/fetch/_call_client.js#L2)

Then you can call methods off the client, for example `es.get()`. You can refer to the documentation for the available methods and the options they take. Index name is usually a field you can supply in the params.

Sorry for the delayed response - my email notifications were not coming in.

---

<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, 1:39pm UTC](https://discuss.elastic.co/t/accessing-to-different-index-from-the-contoroller-in-kibana/57666/5 "2017-07-06T13:39:48Z")

</div>


