1
我目前的父母在與這些文檔相關的彈性搜索(文檔)和子(評論)中編制索引。 我的第一個目標是根據子查詢搜索包含N個以上評論的文檔。這是我如何做的:按ElasticSearch中的子頻率篩選
documents/document/_search
{
"min_score": 0,
"query": {
"has_child" : {
"type" : "comment",
"score_type" : "sum",
"boost": 1,
"query" : {
"range": {
"date": {
"lte": 20130204,
"gte": 20130201,
"boost": 1
}
}
}
}
}
}
我用得分來計算的意見的文件有多少,然後我通過這個量過濾的文件,使用「min_score」。 現在,我的目標是不僅搜索評論,還會搜索與該文檔相關的其他幾個子文檔,並始終基於頻率。類似查詢波紋管:
documents/document/_search
{
"query": {
"match_all": {
}
},
"filter" : {
"and" : [{
"query": {
"has_child" : {
"type" : "comment",
"query" : {
"range": {
"date": {
"lte": 20130204,
"gte": 20130201
}
}
}
}
}
},
{
"or" : [
{"query": {
"has_child" : {
"type" : "comment",
"query" : {
"match": {
"text": "Finally"
}
}
}
}
},
{ "query": {
"has_child" : {
"type" : "comment",
"query" : {
"match": {
"text": "several"
}
}
}
}
}
]
}
]
}
}
上面的查詢工作正常,但它不會像第一個那樣根據頻率進行過濾。由於篩選器是在計算分數之前計算的,因此我無法使用min_score篩選每個子查詢。
對此問題的任何解決方案?
但是,bool查詢不允許我寫(例如條件A AND(條件B OR條件C))這樣的句子。 – mvallebr
當然,如果你使用多個嵌套布爾查詢的話。外部的將有兩個must子句,conditionA和一個額外的bool查詢,只有conditionB和conditionC的應用子句。說得通?這只是一種不同的心態,但你可以實現相同的行爲。 – javanna
其實你是對的,布爾查詢可以做的邏輯...馬斯如何過濾分數單獨? – mvallebr