# Unable to reference "filters" object properly in custom plugin

**URL:** <https://discuss.elastic.co/t/unable-to-reference-filters-object-properly-in-custom-plugin/58907>\
**Category:** Kibana\
**Created:** [August 25, 2016, 9:35am UTC](https://discuss.elastic.co/t/unable-to-reference-filters-object-properly-in-custom-plugin/58907 "2016-08-25T09:35:16Z")\
**Posts on this page:** 4\
**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 25, 2016, 9:35am UTC](https://discuss.elastic.co/t/unable-to-reference-filters-object-properly-in-custom-plugin/58907/1 "2016-08-25T09:35:16Z")

</div>

Hi!

I would like to get help with custom plugin development.

I want to reference the "key" inside the filter object from the controller.  
Below is my filter object.

```
{"meta":{"index":"raw-arm-*","key":"robot_name","value":"test1","disabled":false,"negate":false,"alias":null,"apply":true},"query":{"match":{"robot_name":{"query":"test2","type":"phrase"}}},"$state":{"store":"appState"}},
{"meta":{"index":"raw-arm-*","key":"parts_name","value":"test2","disabled":false,"negate":false,"alias":null,"apply":true},"query":{"match":{"parts_name":{"query":"test2","type":"phrase"}}},"$state":{"store":"appState"}}]

```

However, when I reference the key as filter[0].meta.key , it returns nothing. But I am reference **index**.

Below is my code snippet.

```
// Import module for kibana
import uiModules from 'ui/modules';

// Import d3.js module
import * as d3 from 'd3';

// Pass the plugin name
const module = uiModules.get('sample', []);

// A unique name that defines the controller name
// We are not using the aggregation provided by Kibana interfac3
module.controller('PluginController', function ($scope, timefilter, getAppState, Private, $http, $location, dateFilter) {

  $scope.state = getAppState();

  $scope.$watch('state.$newFilters', function (filters) {
    // Do nothing when the filter was not specified at all
    //if(!filters) return;

    // Example of getting time range
    var range_min = timefilter.getBounds().min;
    var range_max = timefilter.getBounds().max;

    // Flag to decide the target index is arm(0) or run-jump(1)
    var target = 0

    // Variable to store query
    var body = '';

    $scope.meta = filters[0].meta;

    $scope.index = filters[0].meta.index;

    $scope.type = typeof(filters[0].meta);

    // I tried both to see in template but both returned nothing.
    //$scope.key = filters[0].meta.key;

    //$scope.key = filters[0].meta["key"];

```

 ![](https://us1.discourse-cdn.com/elastic/original/2X/2/2b5ea934b25dd793e16696c5a44648e3fdf2d2c8.PNG)

How I can reference the key **key**

Thanks,  
Yu

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [August 26, 2016, 10:47pm UTC](https://discuss.elastic.co/t/unable-to-reference-filters-object-properly-in-custom-plugin/58907/2 "2016-08-26T22:47:54Z")

</div>

Yu,

That is the correct way of accessing that property. You should be able to console.log or place a debugger within the controller to validate. My guess is the issue is something else, possibly due to using "key" as a property on $scope.

---

<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:** [September 12, 2016, 11:59am UTC](https://discuss.elastic.co/t/unable-to-reference-filters-object-properly-in-custom-plugin/58907/3 "2016-09-12T11:59:01Z")

</div>

Hi @tsmalley

My apology for the late reply. I couldn't figure out the way to use **key** as a key so I ended up accessing the **query** key. Below worked perfectly.

```
filters[0].query.match.robot_name.query
filters[1].query.match.parts_name.query
```

---

<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/unable-to-reference-filters-object-properly-in-custom-plugin/58907/4 "2017-07-06T13:39:07Z")

</div>


