es建议查询

好久不见. 提交于 2020-05-03 15:38:40

  在输入的时候,都会给用户一个建议。

1.es中有三种建议器

  Term suggester

  Phrase suggester

  Completion suggester

 

2.字段

  

 

 

3.Term suggester

  term 词条建议器,对给输⼊的⽂本进⾏分词,为每个分词提供词项建议

POST /nba_lastest/_search
{
  "suggest": {
    "my-suggester": {
      "text": "Stev",
      "term": {
        "suggest_mode": "missing",
        "field": "displayNameEn"
      }
    }
  }
}

  效果:

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "suggest" : {
    "my-suggester" : [
      {
        "text" : "stev",
        "offset" : 0,
        "length" : 4,
        "options" : [
          {
            "text" : "seth",
            "score" : 0.5,
            "freq" : 2
          },
          {
            "text" : "stein",
            "score" : 0.5,
            "freq" : 2
          },
          {
            "text" : "steven",
            "score" : 0.5,
            "freq" : 2
          }
        ]
      }
    ]
  }
}

  

4.Phrase suggester

  phrase 短语建议,在term的基础上,会考量多个term之间的关系,⽐如是否同时出现在索 引的原⽂⾥,相邻程度,以及词频等

POST /nba_lastest/_search
{
  "suggest": {
    "my-suggester": {
      "text": "jamse harden",
      "phrase": {
        "field": "displayNameEn"
      }
    }
  }
}

  效果:

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "suggest" : {
    "my-suggester" : [
      {
        "text" : "jamse harden",
        "offset" : 0,
        "length" : 12,
        "options" : [
          {
            "text" : "james harden",
            "score" : 0.0036367897
          },
          {
            "text" : "jamal harden",
            "score" : 0.0022790073
          },
          {
            "text" : "jake harden",
            "score" : 0.001686592
          },
          {
            "text" : "jose harden",
            "score" : 0.001686592
          }
        ]
      }
    ]
  }
}

  

5.Completion suggester Completion 完成建议

  这里需要的是将字段的type修改为competition

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!