<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 匹配查詢 Match 如果需要為不同字段設置不同權重,可以考慮使用 bool 查詢的 should 子句來組合多個 match 查詢,并為每個 match 查詢設置不同的權重。 ``` { "query": { "bool": { "should": [ { "match": { "product_name": { "query": "apple", "boost": 3 } } }, { "match": { "description": { "query": "apple", "boost": 1 } } } ] } } } ``` 上面的查詢將在 product_name 字段和 description 字段中搜索包含 "apple" 的文檔,并為 product_name 字段設置權重為 3,而為 description 字段設置權重為 1。這樣,在計算匹配得分時,product_name 字段的匹配將比 description 字段的匹配更加重要,因為它的權重更高。這種方式可以靈活地控制不同字段的權重,以滿足不同的搜索需求。 ## 精確匹配查詢 Match_pharse match_phrase 查詢是 Elasticsearch 中一種用于精確匹配短語的查詢方式,可以確保查詢字符串中的關鍵詞按照給定的順序在文檔中連續出現。以下是 match_phrase 查詢的用法 #### 簡單用法 match_phrase 查詢可以直接指定一個字段和一個短語進行匹配。 ``` $client = ElasticSearchCLient::getInstance(); $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'match_phrase' => [ 'title' => '開源技術小棧20245直播間' ] ] ] ]; $indexResponse = $client->search($indexParams); ``` ``` $client = ElasticSearchCLient::getInstance(); $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'match_phrase' => [ 'title' => '開源技術小棧20245直播間' ] ] ] ]; $indexResponse = $client->search($indexParams); ``` 查詢結果 ``` "hits": [ { "_index": "resty_product_test_index", "_type": "_doc", "_id": "20245", "_score": 2.3340414, "_source": { "id": 20245, "title": "開源技術小棧20245直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } } ] ``` 如果`'title' => '開源技術小棧'`,則查詢結果 ``` "hits": [ { "_index": "resty_product_test_index", "_type": "_doc", "_id": "2024", "_score": 1.0939294, "_source": { "id": 2024, "title": "開源技術小棧20240724直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20240724直播間" } }, { "_index": "resty_product_test_index", "_type": "_doc", "_id": "20245", "_score": 1.0939294, "_source": { "id": 20245, "title": "開源技術小棧20245直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } } ] ``` #### 位置信息 `match_phrase` 查詢會記錄匹配短語在文檔中的位置信息,可以通過 `slop` 參數指定允許的位置偏移量。 ``` $client = ElasticSearchCLient::getInstance(); $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'match_phrase' => [ 'title' => [ 'query' => '開源技術小棧20245直播間', 'slop' => 2 ] ] ] ] ]; $indexResponse = $client->search($indexParams); ``` ## 多字段查詢 Match multi_match multi_match 查詢可以直接指定一個查詢字符串,然后在多個字段中進行搜索。 #### 簡單用法 ``` $client = ElasticSearchCLient::getInstance(); $query = '開源技術小棧'; $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'multi_match' => [ 'query' => $query, 'fields' => ['title', 'content'], ] ] ] ]; $indexResponse = $client->search($indexParams); ``` 查詢結果 ``` "hits": [ { "_index": "resty_product_test_index", "_type": "_doc", "_id": "2024", "_score": 2.399356, "_source": { "id": 2024, "title": "開源技術小棧20240724直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20240724直播間" } }, { "_index": "resty_product_test_index", "_type": "_doc", "_id": "20245", "_score": 2.399356, "_source": { "id": 20245, "title": "開源技術小棧20245直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } }, { "_index": "resty_product_test_index", "_type": "_doc", "_id": "202457879", "_score": 1.1278633, "_source": { "id": 202457879, "title": "Tinywan", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } } ] ``` 上面的查詢將在`title`和`content`字段中搜索包含 `開源技術小棧` 的文檔。 #### 類型匹配 multi_match 查詢可以通過 type 參數指定匹配的類型,如 "best_fields"、 "most_fields"、 "cross_fields"、 "phrase"、 "phrase_prefix" 等。不同的類型在匹配方式和結果計算上有所不同。 ``` $client = ElasticSearchCLient::getInstance(); $query = '開發者社區'; $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'multi_match' => [ 'query' => $query, 'fields' => ['title', 'content'], "type" => "best_fields" ] ] ] ]; $indexResponse = $client->search($indexParams); ``` ``` "hits": [ { "_index": "resty_product_test_index", "_type": "_doc", "_id": "2024", "_score": 0.7439606, "_source": { "id": 2024, "title": "開源技術小棧20240724直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20240724直播間" } }, { "_index": "resty_product_test_index", "_type": "_doc", "_id": "20245", "_score": 0.7439606, "_source": { "id": 20245, "title": "開源技術小棧20245直播間", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } }, { "_index": "resty_product_test_index", "_type": "_doc", "_id": "202457879", "_score": 0.7439606, "_source": { "id": 202457879, "title": "Tinywan", "content": "開源技術小棧-騰訊云開發者社區,開源技術小棧20245直播間" } } ] ``` 上面的查詢將使用 "best_fields" 類型在`title`和`content`字段中搜索包含短語`開源技術小棧`的文檔。 ## 高級搜索查詢 query_string 在 Elasticsearch 中,query_string 是一種查詢方式,用于在文本字段上執行靈活且強大的搜索操作。query_string 查詢支持使用 Lucene 查詢語法進行高級搜索,可以通過在查詢字符串中指定不同的搜索條件、操作符和邏輯關系來構建復雜的搜索查詢。 #### 簡單的關鍵詞匹配 ``` $client = ElasticSearchCLient::getInstance(); $query = '開發者社區'; $indexParams = [ 'index' => 'resty_product_test_index', 'body' => [ 'query' => [ 'query_string' => [ 'default_field' => 'title', 'query' => $query, ] ] ] ]; $indexResponse = $client->search($indexParams); ``` 上面的查詢將在 `title`字段中搜索包含關鍵詞 "開發者社區" 的文檔。
                  <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>

                              哎呀哎呀视频在线观看