我來自Solr背景,試圖在Elasticsearch中找到相當於"tagging" and "excluding"的地方。如何從一個方面排除過濾器?
在以下示例中,如何從prices
構面的計算中排除price
過濾器?換言之,prices
方面應考慮除price
之外的所有過濾器。
{
query : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"and" : [
{
"term" : {
"colour" : "Red"
}
},
{
"term" : {
"feature" : "Square"
}
},
{
"term" : {
"feature" : "Shiny"
}
},
{
"range" : {
"price" : {
"from" : "10",
"to" : "20"
}
}
}
]
}
}
},
"facets" : {
"colours" : {
"terms" : {
"field" : "colour"
}
},
"features" : {
"terms" : {
"field" : "feature"
}
},
"prices" : {
"statistical" : {
"field" : "price"
}
}
}
}
恐怕這似乎不起作用。 「價格」過濾器不適用於搜索結果。此外,價格過濾器仍然包含在「價格」面的計算中。 – gjb 2013-03-27 00:27:02
它似乎在爲我工作 - https://gist.github.com/imotov/5250599 – imotov 2013-03-27 00:35:12
謝謝,這完美的作品。我嵌套查詢的方式存在問題。只有一個最後的想法:有沒有辦法實現這一點,而沒有重複?我有很多方面,因此在每個其他方面添加'facet_filter'遠非理想。 – gjb 2013-03-27 00:58:42