簡體   English   中英

排除具有不同字段的重要術語聚合

[英]Exclude Significant Term Aggregation With Different Field

是否可以使用要過濾的多個字段來過濾重要術語聚合的桶列表結果? 我正在嘗試使用 ES 創建基於本文的推薦功能,該文章位於中等https://towardsdatascience.com/how-to-build-a-recommendation-engine-quick-and-simple-aec8c71a823e

我將搜索數據存儲為對象數組而不是字符串數組,因為我需要過濾其他字段以獲得正確的存儲桶列表結果。 這是索引映射:

{
  "mapping": {
    "properties": {
      "user": {
        "type": "keyword",
        "ignore_above": 256
      },
      "comic_subscribes": {
        "properties": {
          "genres": {
            "type": "keyword",
            "ignore_above": 256
          },
          "id": {
            "type": "keyword",
            "ignore_above": 256
          },
          "type": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

我有2個條件要過濾:

  1. Comic_subscribes.type 只能是“serial”
  2. Comic_subscribes.genre 不得在“hentai”或“echii”中

我已經嘗試了兩種方法來應用條件。 首先,我嘗試使用這樣的 bool 查詢對其進行過濾:

{
    "size": 0,
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "comic_subscribes.id": "1"
                    }
                }
            ],
            "minimum_should_match": 1,
            "filter": {
                "term": {
                    "comic_subscribes.type": "serial"
                }
            },
            "must_not": [
                {
                    "bool": {
                        "should": [
                            {
                                "term": {
                                    "comic_subscribes.genres": "hentai"
                                }
                            },
                            {
                                "term": {
                                    "comic_subscribes.genres": "echii"
                                }
                            }
                        ],
                        "minimum_should_match": 1
                    }
                }
            ]
        }
    },
    "aggs": {
        "recommendations": {
            "significant_terms": {
                "field": "comic_subscribes.id",
                "exclude": ["1"],
                "min_doc_count": 1,
                "size": 10
            }
        }
    }
}

和過濾聚合方法:

{
    "size": 0,
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "comic_subscribes.id": "1"
                    }
                }
            ],
            "minimum_should_match": 1
        }
    },
    "aggs": {
        "filtered": {
            "filter": {
                "bool": {
                    "filter": {
                        "term": {
                            "comic_subscribes.type": "serial"
                        }
                    },
                    "must_not": [
                        {
                            "bool": {
                                "should": [
                                    {
                                        "term": {
                                            "comic_subscribes.genres": "hentai"
                                        }
                                    },
                                    {
                                        "term": {
                                            "comic_subscribes.genres": "echii"
                                        }
                                    }
                                ],
                                "minimum_should_match": 1
                            }
                        }
                    ]
                }
            },
            "aggs": {
                "recommendations": {
                    "significant_terms": {
                        "field": "comic_subscribes.id",
                        "exclude": ["1"],
                        "min_doc_count": 1,
                        "size": 10
                    }
                }
            }
        }
    }
}

但是,這兩種方法都給了我未經過濾的漫畫清單。 有沒有其他方法可以達到這些要求的條件? 我是否應該再創建一個存儲預過濾漫畫列表的字段以用作源字段重要術語? 非常感謝。

好的,兄弟們。 我認為沒有使用不同字段過濾聚合重要術語桶列表結果的選項方法。

基於 elasticsearch 文檔重要術語聚合參數,指術語聚合過濾值 除了使用分區表達式過濾和使用精確值過濾值之外沒有其他選擇(我一直在使用上面的“排除”參數)。

因此,我通過獲取要排除的漫畫 ID 並將其存儲為數組中的 excludeComics 變量來創建其他方式。 然后在排除參數中使用 excludeComics var。 和繁榮,你有go。 過濾的重要術語聚合桶列表結果。

暫無
暫無

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

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