簡體   English   中英

Elasticsearch使用后台過濾器嵌套了重要的術語聚合

[英]Elasticsearch nested significant terms aggregation with background filter

我很難將后台過濾器應用於嵌套的重要術語聚合, 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。

謝謝

您似乎遇到了以下問題:在后台過濾器中,您需要“返回”父上下文,以便根據父文檔的字段定義背景過濾器。

此時您需要一個reverse_nested查詢,但這不存在。

避免這種情況的一種方法是將app_id字段添加到嵌套文檔中,以便您可以在后台過濾器上下文中使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM