ik分词器

  ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;

       ik_smart: 会做最粗粒度的拆分,会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。 比如这个时候搜索“共和国” --> 中华人民共和国和国歌,搜到吗???? 显然不能搜索的到。

 

PUT /life
{
  "mappings": {
    "properties": {
      "text":{
        "type":"text",
        "analyzer": "ik_max_word"
      }
    }
  }
}

 

  添加数据

PUT /life/_bulk
{ "index": { "_id": "1"} }
{ "text": "明月几时有,把酒问青天" }
{ "index": { "_id": "2"} }
{ "text": "不知天上宫阙,今是何年" }
{ "index": { "_id": "3"} }
{ "text": "于千万之中于千万年之中" }
{ "index": { "_id": "4"} }
{ "text": "时间无涯的荒野里" }
{ "index": { "_id": "5"} }
{ "text": "生命诚可贵,爱情价更高" }

  查询

GET /life/_search
{
  "query": {
    "match":{
      "text":"时间等于生命"
    }
  }
}

--------------------------------------------------

{
  "took" : 975,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.4691956,
    "hits" : [
      {
        "_index" : "life",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.4691956,
        "_source" : {
          "text" : "时间无涯的荒野里"
        }
      },
      {
        "_index" : "life",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.3670106,
        "_source" : {
          "text" : "生命诚可贵,爱情价更高"
        }
      }
    ]
  }
}

 

 

       

 

posted on 2021-08-28 12:01  溪水静幽  阅读(28)  评论(0)    收藏  举报