現在我有以下形式的一些資料:
df = pd.DataFrame([['foo','some text',1, 13],['foo','Another text',2, 4],['foo','Third text',3, 10],['bar','Text1',2, 25], ['bar','Long text',1, 17],['num','short text',3, 0],['num','fifth text',3, 8]], index = range(1,8), columns = ['category','text','label', 'count'])
我已將檔案放入 es 索引中,并嘗試在獲取大于 0 且小于 10 的“計數”以及不是“foo”的“類別”的條件下進行搜索。
我嘗試在布爾查詢的“filter”子句中使用“none”子句,但它給出了“沒有為 [none] 注冊查詢”的錯誤。
text: "text"
data = json.dumps({
"query":{
"bool":{
"should":[
{
"match":{
"text":text
}
}
],
"filter": [
{
"range": {
"count": {
"from": 0,
"to": 10
}
}
},
{
"none": {
"term": {
"category.keyword": "foo"
}
}
}
]
}
}
})
所以我現在使用“must_not”子句,如下所示:
text: "text"
data = json.dumps({
"query":{
"bool":{
"should":[
{
"match":{
"text":text
}
}
],
"filter": [
{
"range": {
"count": {
"from": 0,
"to": 10
}
}
}
]
,
"must_not":[
{
"term": {
"category.keyword": "foo"
}
}
]
}
}
})
有沒有辦法在“過濾器”子句中使用“無”并使查詢更有效地作業?謝謝!
uj5u.com熱心網友回復:
如檔案中所述,該子句忽略了評分,因此即使在過濾子句之外包含must_not子句,也不會對查詢的性能(上面使用)產生影響。must_not
子句(查詢)不得出現在匹配的檔案中。子句在過濾器背景關系中執行,這意味著忽略評分并考慮快取子句。因為忽略了評分,所以回傳所有檔案的 0 分。
除此之外,沒有none查詢,而是只有Match None 查詢,它不匹配任何檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464125.html
上一篇:PHP生成圖形驗證碼
