[英]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個條件要過濾:
我已經嘗試了兩種方法來應用條件。 首先,我嘗試使用這樣的 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
}
}
}
}
}
}
但是,這兩種方法都給了我未經過濾的漫畫清單。 有沒有其他方法可以達到這些要求的條件? 我是否應該再創建一個存儲預過濾漫畫列表的字段以用作源字段重要術語? 非常感謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.