Unable to reference "filters" object properly in custom plugin


(Yu Watanabe) #1

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"];

How I can reference the key key

Thanks,
Yu


(Tyler Smalley) #2

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.


(Yu Watanabe) #3

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

(system) #4