我很难将背景过滤器应用于嵌套的重要术语聚合,bg_count
始终为0.
我正在索引包含ID和时间戳的文章视图,并且在单个索引上有多个应用程序。我希望前景和背景设置与同一个应用程序相关,所以我试图在boo查询和后台过滤器中的app_id
字段上应用术语过滤器。 article_views
是一个嵌套对象,因为我希望能够在timestamp
上使用范围过滤器查询视图,但我还没有这样做。
映射:
{
"article_views": {
"type": "nested",
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"app_id": {
"type": "string",
"index": "not_analyzed"
}
}
查询:
{
"aggregations": {
"articles": {
"nested": {
"path": "article_views"
},
"aggs": {
"articles": {
"significant_terms": {
"field": "article_views.id",
"size": 5,
"background_filter": {
"term": {
"app_id": "17"
}
}
}
}
}
}
},
"query": {
"bool": {
"must": [
{
"term": {
"app_id": "17"
}
},
{
"nested": {
"path": "article_views",
"query": {
"terms": {
"article_views.id": [
"1",
"2"
]
}
}
}
}
]
}
}
}
正如我所说,在我的结果中,bg_count
始终为0,让我担心。如果重要术语位于未嵌套的其他字段上,则background_filter
可以正常工作。
Elasticsearch版本为2.2。
由于
答案 0 :(得分:1)
您似乎正在点击后台过滤器中的following issue,您需要"返回"到父上下文,以便根据父文档的字段定义背景过滤器。
此时您需要String queryExtractAll =
"SELECT DISTINCT ?Num ?Owner ?Title ?Content WHERE \n { "
+ "?Complaint skyt:numofRead ?Num;"
+ "skyt:owner ?Owner;"
+ "skyt:title ?Title;"
+ "skyt:content ?Content"
+ " FILTER (?Num >= 1) " + ".}\n"
+ " ORDER BY DESC (?Num) ";
查询,但这并不存在。
避免这种情况的一种方法是将reverse_nested
字段添加到嵌套文档中,以便您可以在后台过滤器上下文中使用它。