国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ElasticSearch系列 - SpringBoot整合ES:多字段查詢 multi_match

這篇具有很好參考價(jià)值的文章主要介紹了ElasticSearch系列 - SpringBoot整合ES:多字段查詢 multi_match。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1. 什么是 ElasticSearch 的 multi_match 查詢?

有時(shí)用戶需要在多個(gè)字段中查詢關(guān)鍵詞,除了使用布爾查詢封裝多個(gè)match查詢之外,可替代的方案是使用multi_match??梢栽趍ulti_match的query子句中組織數(shù)據(jù)匹配規(guī)則,并在fields子句中指定需要搜索的字段列表。

以下是一個(gè)示例multi-match查詢的語(yǔ)法:

{
  "query": {
    "multi_match": {
      "query": "搜索文本",
      "fields": ["字段1", "字段2", "字段3"]
    }
  }
}

在上面的查詢中,我們指定了要搜索的文本和要搜索的字段列表。ElasticSearch將搜索所有指定的字段,并將它們合并為一個(gè)結(jié)果集。

2. 如何在 multi_match 查詢中指定查詢字段?

在 Elasticsearch 的 multi_match 查詢中,可以使用 “fields” 參數(shù)來(lái)指定要查詢的字段。該參數(shù)接受一個(gè)數(shù)組,其中包含要查詢的字段名稱。

① 構(gòu)造數(shù)據(jù):

PUT /my_index
{
  "mappings": {
    "properties": {
      "title":{
        "type": "text"
      },
      "content":{
        "type": "text"
      }
    }
  }
}

PUT /my_index/_doc/1
{
  "title": "Jindu Fashion Couple Romantic Theme Hotel",
  "content": "Qingdao City"
}

PUT /my_index/_doc/2
{
  "title": "Jindu Jiayi Holiday Inn",
  "content": "Beijing City"
}

PUT /my_index/_doc/3
{
  "title": "Jindu Xinxin 24 hour Hotel",
  "content": "Huaibei City"
}

② 以下查詢將在 “title” 和 “content” 字段中搜索包含 “Beijing” 和 “Xinxin” 的文檔:

{
  "query": {
    "multi_match": {
      "query": "Beijing Xinxin",
      "fields": ["title", "content"]
    }
  }
}

如果未指定 “fields” 參數(shù),則默認(rèn)情況下將在所有字段中搜索。

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.9808292,
    "hits" : [
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.9808292,
        "_source" : {
          "title" : "Jindu Jiayi Holiday Inn",
          "content" : "Beijing City"
        }
      },
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.9808292,
        "_source" : {
          "title" : "Jindu Xinxin 24 hour Hotel",
          "content" : "Huaibei City"
        }
      }
    ]
  }
}

3. 如何在 multi_match 查詢中指定查詢權(quán)重?

在 Elasticsearch 的 multi_match 查詢中,可以使用 “fields” 參數(shù)來(lái)指定要搜索的字段,并使用 “^” 符號(hào)來(lái)指定每個(gè)字段的權(quán)重。

例如:“title” 的權(quán)重為 5,“content” 的權(quán)重為 2。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-420555.html

GET /my_index/_search
{
  "query": {
    "multi_match": {
      "query": "Beijing Xinxin",
      "fields": ["title^5","content^2"]
    }
  }
}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 4.904146,
    "hits" : [
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 4.904146,
        "_source" : {
          "title" : "Jindu Xinxin 24 hour Hotel",
          "content" : "Huaibei City"
        }
      },
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.9616584,
        "_source" : {
          "title" : "Jindu Jiayi Holiday Inn",
          "content" : "Beijing City"
        }
      }
    ]
  }
}

4. SpringBoot整合ES實(shí)現(xiàn) multi_match 查詢

@Slf4j
@Service
public class ElasticSearchImpl {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    public void searchUser() throws IOException {
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("Beijing Xinxin", "title", "content");
        searchSourceBuilder.query(multiMatchQueryBuilder);

        SearchRequest searchRequest = new SearchRequest(new String[]{"hotel"},searchSourceBuilder);
        SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
        System.out.println(searchResponse);
    }
}

到了這里,關(guān)于ElasticSearch系列 - SpringBoot整合ES:多字段查詢 multi_match的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • ElasticSearch系列 - SpringBoot整合ES:多個(gè)精確值查詢 terms

    ElasticSearch - SpringBoot整合ES:多個(gè)精確值查詢 terms 01. ElasticSearch terms 查詢支持的數(shù)據(jù)類型 在Elasticsearch中,terms查詢支持多種數(shù)據(jù)類型,包括: 字符串類型:可以將多個(gè)字符串值作為數(shù)組傳遞給terms查詢,以匹配包含任何一個(gè)指定字符串值的文檔。 數(shù)值類型:可以將多個(gè)數(shù)值作

    2024年02月16日
    瀏覽(27)
  • ElasticSearch系列 - SpringBoot整合ES之全文搜索匹配查詢 match

    官方文檔地址:https://www.elastic.co/guide/en/elasticsearch/reference/index.html 權(quán)威指南:https://www.elastic.co/guide/cn/elasticsearch/guide/current/structured-search.html 1. 數(shù)據(jù)準(zhǔn)備 官方測(cè)試數(shù)據(jù)下載地址:https://download.elastic.co/demos/kibana/gettingstarted/accounts.zip ,數(shù)據(jù)量很大,我們自己構(gòu)造數(shù)據(jù)吧。 2. m

    2023年04月08日
    瀏覽(32)
  • ElasticSearch系列 - SpringBoot整合ES:短語(yǔ)匹配查詢 match_phrase

    1. ElasticSearch match_phrase查詢是什么?它與match查詢有什么區(qū)別? match_phrase查詢是一種用于匹配短語(yǔ)的查詢方式,可以用于精確匹配多個(gè)單詞組成的短語(yǔ)。它會(huì)將查詢字符串分解成單詞,然后按照順序匹配文檔中的單詞,只有當(dāng)文檔中的單詞順序與查詢字符串中的單詞順序完全

    2024年02月12日
    瀏覽(18)
  • ElasticSearch系列 - SpringBoot整合ES:查詢條件 query 和過濾條件 filter 的區(qū)別

    01. Elasticsearch 查詢條件和過濾條件的區(qū)別? Elasticsearch中的查詢條件和過濾條件都是用于搜索和過濾文檔的條件,但它們之間有一些區(qū)別。 查詢條件是用于計(jì)算文檔相關(guān)度得分的條件,它會(huì)將所有符合條件的文檔按照相關(guān)度得分從高到低排序,并返回前N個(gè)文檔。查詢條件可以

    2024年02月14日
    瀏覽(25)
  • ElasticSearch序列 - SpringBoot整合ES:范圍查詢 range

    01. ElasticSearch range查詢是什么? Elasticsearch 中的 range 查詢可以用于查詢某個(gè)字段在一定范圍內(nèi)的文檔。 range 查詢可同時(shí)提供包含和不包含這兩種范圍表達(dá)式,可供組合的選項(xiàng)如下: gt : 大于(greater than) lt : 小于(less than) gte : = 大于或等于(greater than or equal to) lte : = 小于

    2024年02月09日
    瀏覽(27)
  • ElasticSearch序列 - SpringBoot整合ES:根據(jù)指定的 ids 查詢

    1. ElasticSearch 根據(jù) ids 查詢文檔 ① 索引文檔,構(gòu)造數(shù)據(jù) ② 查詢文檔 id 為 1 或者 2 的文檔: 我們索引文檔時(shí),文檔的id為整型,為什么查詢出來(lái)的文檔 id為字符串類型呢?如果我們使用字符串類型的文檔id查詢呢? 可以看到仍然可以查詢到匹配的文檔。 在Elasticsearch中,文檔

    2024年02月11日
    瀏覽(23)
  • ElasticSearch系列 - SpringBoot整合ES:ElasticSearch分析器

    1. ElasticSearch match 文本搜索的過程? Elasticsearch 的 match 查詢是一種基于文本匹配的查詢方式,它的搜索過程如下: ① 將查詢字符串分詞:Elasticsearch 會(huì)將查詢字符串分成一個(gè)個(gè)詞項(xiàng)(term),并去除停用詞(如“的”、“是”等常用詞匯)和標(biāo)點(diǎn)符號(hào)等無(wú)意義的字符。 ② 構(gòu)建

    2023年04月18日
    瀏覽(25)
  • ElasticSearch系列 - SpringBoot整合ES:分析器

    1. ElasticSearch match 文本搜索的過程? Elasticsearch 的 match 查詢是一種基于文本匹配的查詢方式,它的搜索過程如下: ① 將查詢字符串分詞:Elasticsearch 會(huì)將查詢字符串分成一個(gè)個(gè)詞項(xiàng)(term),并去除停用詞(如“的”、“是”等常用詞匯)和標(biāo)點(diǎn)符號(hào)等無(wú)意義的字符。 ② 構(gòu)建

    2024年02月06日
    瀏覽(24)
  • ElasticSearch系列 - SpringBoot整合ES:實(shí)現(xiàn)搜索結(jié)果排序 sort

    00. 數(shù)據(jù)準(zhǔn)備 01. Elasticsearch 默認(rèn)的排序方式是什么? ElasticSearch 默認(rèn)的排序方式是相關(guān)性排序。相關(guān)性排序是根據(jù)查詢條件與文檔的匹配程度來(lái)計(jì)算每個(gè)文檔的相關(guān)性得分,然后按照得分從高到低進(jìn)行排序。相關(guān)性排序是 ElasticSearch 中最常用的排序方式,因?yàn)樗梢愿鶕?jù)查詢

    2024年02月02日
    瀏覽(22)
  • ElasticSearch系列 - SpringBoot整合ES:restHighLevelClient.count(countRequest, RequestOptions.DEFAULT)

    restHighLevelClient.count(countRequest, RequestOptions.DEFAULT) 是 Elasticsearch Java High Level REST Client 中用于執(zhí)行計(jì)數(shù)請(qǐng)求的方法。 具體來(lái)說(shuō),它接受兩個(gè)參數(shù): countRequest:一個(gè) CountRequest 對(duì)象,表示計(jì)數(shù)請(qǐng)求的參數(shù),包括要計(jì)數(shù)的索引、查詢條件等。 RequestOptions.DEFAULT:一個(gè) RequestOptions 對(duì)象

    2024年02月08日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包