<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 最佳字段 假設我們有一個讓用戶搜索博客文章的網站(允許多字段搜索,最佳字段查詢),就像這兩份文檔一樣: ```Javascript PUT /my_index/my_type/1 { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } PUT /my_index/my_type/2 { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } ``` // SENSE: 110_Multi_Field_Search/15_Best_fields.json 用戶輸入了"Brown fox",然后按下了搜索鍵。我們無法預先知道用戶搜索的詞條會出現在博文的title或者body字段中,但是用戶是在搜索和他輸入的單詞相關的內容。右眼觀察,以上的兩份文檔中,文檔2似乎匹配的更好一些,因為它包含了用戶尋找的兩個單詞。 讓我們運行下面的bool查詢: ```Javascript { "query": { "bool": { "should": [ { "match": { "title": "Brown fox" }}, { "match": { "body": "Brown fox" }} ] } } } ``` // SENSE: 110_Multi_Field_Search/15_Best_fields.json 然后我們發現文檔1的分值更高: ```Javascript { "hits": [ { "_id": "1", "_score": 0.14809652, "_source": { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } }, { "_id": "2", "_score": 0.09256032, "_source": { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } } ] } ``` 要理解原因,想想bool查詢是如何計算得到其分值的: * 1.運行should子句中的兩個查詢 * 2.相加查詢返回的分值 * 3.將相加得到的分值乘以匹配的查詢子句的數量 * 4.除以總的查詢子句的數量 文檔1在兩個字段中都包含了brown,因此兩個match查詢都匹配成功并擁有了一個分值。文檔2在body字段中包含了brown以及fox,但是在title字段中沒有出現任何搜索的單詞。因此對body字段查詢得到的高分加上對title字段查詢得到的零分,然后在乘以匹配的查詢子句數量1,最后除以總的查詢子句數量2,導致整體分值比文檔1的低。 在這個例子中,title和body字段是互相競爭的。我們想要找到一個最佳匹配(Best-matching)的字段。 如果我們不是合并來自每個字段的分值,而是使用最佳匹配字段的分值作為整個查詢的整體分值呢?這就會讓包含有我們尋找的兩個單詞的字段有更高的權重,而不是在不同的字段中重復出現的相同單詞。 #### dis_max查詢 相比使用bool查詢,我們可以使用dis_max查詢(Disjuction Max Query)。Disjuction的意思"OR"(而Conjunction的意思是"AND"),因此Disjuction Max Query的意思就是返回匹配了任何查詢的文檔,并且分值是產生了最佳匹配的查詢所對應的分值: ```Javascript { "query": { "dis_max": { "queries": [ { "match": { "title": "Brown fox" }}, { "match": { "body": "Brown fox" }} ] } } } ``` // SENSE: 110_Multi_Field_Search/15_Best_fields.json 它會產生我們期望的結果: ```Javascript { "hits": [ { "_id": "2", "_score": 0.21509302, "_source": { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } }, { "_id": "1", "_score": 0.12713557, "_source": { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } } ] } ``` <!-- === Best Fields Imagine that we have a website that allows ((("multifield search", "best fields queries")))((("best fields queries")))users to search blog posts, such as these two documents: [source,js] -------------------------------------------------- PUT /my_index/my_type/1 { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } PUT /my_index/my_type/2 { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } -------------------------------------------------- // SENSE: 110_Multi_Field_Search/15_Best_fields.json The user types in the words ``Brown fox'' and clicks Search. We don't know ahead of time if the user's search terms will be found in the `title` or the `body` field of the post, but it is likely that the user is searching for related words. To our eyes, document 2 appears to be the better match, as it contains both words that we are looking for. Now we run the following `bool` query: [source,js] -------------------------------------------------- { "query": { "bool": { "should": [ { "match": { "title": "Brown fox" }}, { "match": { "body": "Brown fox" }} ] } } } -------------------------------------------------- // SENSE: 110_Multi_Field_Search/15_Best_fields.json And we find that this query gives document 1 the higher score: [source,js] -------------------------------------------------- { "hits": [ { "_id": "1", "_score": 0.14809652, "_source": { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } }, { "_id": "2", "_score": 0.09256032, "_source": { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } } ] } -------------------------------------------------- To understand why, think about how the `bool` query ((("bool query", "relevance score calculation")))((("relevance scores", "calculation in bool queries")))calculates its score: 1. It runs both of the queries in the `should` clause. 2. It adds their scores together. 3. It multiplies the total by the number of matching clauses. 4. It divides the result by the total number of clauses (two). Document 1 contains the word `brown` in both fields, so both `match` clauses are successful and have a score. Document 2 contains both `brown` and `fox` in the `body` field but neither word in the `title` field. The high score from the `body` query is added to the zero score from the `title` query, and multiplied by one-half, resulting in a lower overall score than for document 1. In this example, the `title` and `body` fields are competing with each other. We want to find the single _best-matching_ field. What if, instead of combining the scores from each field, we used the score from the _best-matching_ field as the overall score for the query? This would give preference to a single field that contains _both_ of the words we are looking for, rather than the same word repeated in different fields. [[dis-max-query]] ==== dis_max Query Instead of the `bool` query, we can use the `dis_max` or _Disjunction Max Query_. Disjunction means _or_((("dis_max (disjunction max) query"))) (while conjunction means _and_) so the Disjunction Max Query simply means _return documents that match any of these queries, and return the score of the best matching query_: [source,js] -------------------------------------------------- { "query": { "dis_max": { "queries": [ { "match": { "title": "Brown fox" }}, { "match": { "body": "Brown fox" }} ] } } } -------------------------------------------------- // SENSE: 110_Multi_Field_Search/15_Best_fields.json This produces the results that we want: [source,js] -------------------------------------------------- { "hits": [ { "_id": "2", "_score": 0.21509302, "_source": { "title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis." } }, { "_id": "1", "_score": 0.12713557, "_source": { "title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen." } } ] } -------------------------------------------------- -->
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看