我在Kibana3的自定义面板中有两个过滤器:
request = request.query(
$scope.ejs.FilteredQuery(
boolQuery,
filterSrv.getBoolFilter(filterSrv.ids()) // has to be merged with BoolFilter2
))
.size($scope.panel.size);
这适用于两个滤镜中的任何一个,但我想用两个对象进行过滤,但我不知道如何合并它们。有人可以帮忙吗?
答案 0 :(得分:0)
Kibana 3过滤器可以设置为"或者#34;模式而不是"必须"。
这会转换为如下所示的过滤器:
{
"filter": {
"bool": {
"should": [
{
"fquery": {
"query": {
"query_string": {
"query": "test1"
}
},
"_cache": true
}
},
{
"fquery": {
"query": {
"query_string": {
"query": "test2"
}
},
"_cache": true
}
}
]
}
}
}
以下是在Kibana 3中处理该问题的filterSrv代码:https://github.com/elasticsearch/kibana/blob/3.0/src/app/services/filterSrv.js#L144
this.getBoolFilter = function(ids) {
var bool = ejs.BoolFilter();
// there is no way to introspect the BoolFilter and find out if it has a filter. We must keep note.
var added_a_filter = false;
_.each(ids,function(id) {
if(dashboard.current.services.filter.list[id].active) {
added_a_filter = true;
switch(dashboard.current.services.filter.list[id].mandate)
{
case 'mustNot':
bool.mustNot(self.getEjsObj(id));
break;
case 'either':
bool.should(self.getEjsObj(id));
break;
default:
bool.must(self.getEjsObj(id));
}
}
});
// add a match filter so we'd get some data
if (!added_a_filter) {
bool.must(ejs.MatchAllFilter());
}
return bool;
};
this.getEjsObj = function(id) {
return self.toEjsObj(dashboard.current.services.filter.list[id]);
};
您可以修改该函数以获取将任务设置为任意的可选参数。