您当前的位置: 首页 >  I.T10001 搜索

ES7.16.2基础操作之搜索推荐ngram(八)

I.T10001 发布时间:2021-12-27 17:13:01 ,浏览量:5

##ngram高性能分词搜索(edge ngram将每个单词切分搜索)
##如:hello world,可拆分如下:
##h
##he
##hel
##hell
##hello

##w
##wo
##wor
##worl
##world

##1、建索引,指定自定义分词器
PUT /person
{
  "settings": {
    "analysis": {
      "filter": {
        "autocomplete_filter":{
          "type":"edge_ngram",
          "min_gram":1,
          "max_gram":20
        }
      },
      "analyzer": {
        "autocomplete":{
          "type":"custom",
          "tokenizer":"standard",
          "filter":[
            "lowercase",
            "autocomplete_filter"
          ]
        }
      }
    }
  }
}

##2、查看分词类型
GET person/_analyze
{
  "analyzer": "autocomplete",
  "text": "hello world"
}

##3、设置索引分词器类型
PUT person/_mapping
{
  "properties":{
    "title":{
      "type":"text",
      "analyzer":"autocomplete",
      "search_analyzer":"standard"
    }
  }
}


##4、插入数据
PUT person/_bulk
{"index":{"_id":1}}
{"id":1,"title":"hello world"}
{"index":{"_id":2}}
{"id":2,"title":"hello cat"}
{"index":{"_id":3}}
{"id":3,"title":"hello dog"}
{"index":{"_id":4}}
{"id":4,"title":"hello tom"}
{"index":{"_id":5}}
{"id":5,"title":"hello we"}
{"index":{"_id":6}}
{"id":6,"title":"win 10"}

##5、查询
GET person/_search
{
  "query": {
   "match_phrase": {
     "title": "hello w"
   }
  }
}


关注
打赏
1688896170
查看更多评论

I.T10001

暂无认证

  • 5浏览

    0关注

    154博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0839s