2016-07-09 75 views
0
{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "bool": { 
      "should": [ 
       { 
       "term": { 
        "content": { 
        "value": "遠磐", 
        "boost": 5757544300000000000 
        } 
       } 
       }, 
       { 
       "term": { 
        "title": { 
        "value": "遠磐", 
        "boost": 5757544300000000000 
        } 
       } 
       } 
      ], 
      "minimum_should_match": "1" 
      } 
     }, 
     { 
      "bool": { 
      "should": [ 
       { 
       "term": { 
        "title": { 
        "value": "互聯", 
        "boost": 6456151 
        } 
       } 
       }, 
       { 
       "term": { 
        "content": { 
        "value": "杭州遠磐互聯科技有限公司", 
        "boost": 3.3149317e+37 
        } 
       } 
       } 
      ], 
      "minimum_should_match": "1" 
      } 
     } 
     ] 
    } 
    }, 
    "from": 0, 
    "size": 10 
} 

當我在搜索結果中創建彈性搜索查詢時,發生錯誤。在ElasticSearch中查詢時發生錯誤

我不知道這個錯誤。

錯誤:

IndexOutOfBoundsException[docID must be >= 0 and < maxDoc=158 (got docID=2147457971)] 

和所有命中的得分是零。

enter image description here 整個錯誤:

任何幫助,請!

Regards

+0

爲什麼你必須有另一個布爾?如果你可以上傳你的需求和你的樣本文件,會更有幫助嗎? –

+0

該要求可描述爲sql如下: 從db 選擇文檔 其中(field1 =「XXXX」或field2 =「*****」)和(field1 =「$$$$」或field3 =「&&&&」) – Daniel

+0

我發佈了正確的查詢作爲答案,希望能夠解決您的問題。 –

回答

1

我發表這篇文章作爲答案,因爲它不能張貼爲評論。這是優化的查詢。 緩存過濾器時最好使用過濾器而不是查詢。你應該避免給予如此巨大的數字,因爲它是資源飢渴。嘗試相對較小的數字。

{ 
    "query": { 
    "bool": { 
     "must": { 
     "match_all": {} 
     }, 
     "filter": { 
     "and": [ 
      { 
      "or": [ 
       { 
       "term": { 
        "content": "遠磐" 
       } 
       }, 
       { 
       "term": { 
        "title": "遠磐" 
       } 
       } 
      ] 
      }, 
      { 
      "or": [ 
       { 
       "term": { 
        "content": "互聯" 
       } 
       }, 
       { 
       "term": { 
        "title": "杭州遠磐互聯科技有限公司" 
       } 
       } 
      ] 
      } 
     ] 
     }, 
     "should": [ 
     { 
      "term": { 
      "content": "遠磐", 
      "boost": 10 
      } 
     }, 
     { 
      "term": { 
      "title": "遠磐", 
      "boost": 5 
      } 
     }, 
     { 
      "term": { 
      "content": "互聯", 
      "boost": 3 
      } 
     }, 
     { 
      "term": { 
      "title": "杭州遠磐互聯科技有限公司", 
      "boost": 20 
      } 
     } 
     ], 
     "minimum_should_match": 1, 
     "boost": 1 
    } 
    }, 
    "from":0, 
    "size":10 
} 
+0

另一個問題是,所有的條款都有自己的權重,但過濾器不支持提升。 – Daniel

+0

你可以將這個查詢轉換成一個bool查詢,把這些過濾器放入必須的部分,並在bool查詢的應該部分應用boost,你可以在這裏閱讀更多https://www.elastic.co/guide/en/elasticsearch/ reference/current/query-dsl-bool-query.html –

+0

我已將查詢轉換爲一個bool查詢,並將所有必須的術語放在過濾器中,但它也有相同的錯誤。該術語的權重是否太大,導致ElasticSearch提升出現一些錯誤?該術語的最大權重約爲3.3149317e + 37。 – Daniel

相關問題