elasticsearch term suggester 中文

发布于 2022-09-11 23:12:44 字数 2998 浏览 38 评论 0

term suggester上说明:

analyzer
The analyzer to analyse the suggest text with. Defaults to the search analyzer of the suggest field.
put test-chinese

PUT test-chinese/_mapping/message
{
      "properties": {
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          },
          "analyzer": "ik_max_word",
          "search_analyzer": "ik_smart"
        },
        "name": {
          "type": "keyword"
        }
      }
    }


PUT test-chinese/message/1
{
  "name":"股市投资稳赚不赔必修课:如何做好仓位管理和情绪管理",
  "content":"股市投资稳赚不赔必修课:如何做好仓位管理和情绪管理"
}

PUT test-chinese/message/2
{
  "name":"股市投资",
  "content":"股市投资稳赚不赔必修课:如何做好仓位管理和情绪管理"
}
POST /test-chinese/_search
{ 
  "suggest": {
    "first-suggestion": {
      "text": "股市",
      "term": {
        "suggest_mode": "always",
        "min_word_length":10,
        "field": "name"
      }
    },
    "second-suggestion": {
      "text": "股市",
      "term": {
        "suggest_mode": "popular",
        "min_word_length":2,
        "field": "name",
        "analyzer":"ik_max_word" 
      }
    },
    "third-suggestion": {
      "text": "股市",
      "term": {
        "suggest_mode": "missing",
        "min_word_length":2,
        "field": "name",
        "string_distance": "ngram"
      }
    },
    "foutrh-suggestion": {
      "text": "股市",
      "term": {
        "suggest_mode": "popular",
        "field": "content"
      }
    },
    "fifth-suggestion": {
      "text": "股市",
      "term": {
        "suggest_mode": "always",
        "field": "content"
      }
    }
  }
}

结果是:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "fifth-suggestion": [
      {
        "text": "股市",
        "offset": 0,
        "length": 2,
        "options": []
      }
    ],
    "first-suggestion": [
      {
        "text": "股市",
        "offset": 0,
        "length": 2,
        "options": []
      }
    ],
    "foutrh-suggestion": [
      {
        "text": "股市",
        "offset": 0,
        "length": 2,
        "options": []
      }
    ],
    "second-suggestion": [
      {
        "text": "股市",
        "offset": 0,
        "length": 2,
        "options": []
      }
    ],
    "third-suggestion": [
      {
        "text": "股市",
        "offset": 0,
        "length": 2,
        "options": [
          {
            "text": "股市投资",
            "score": 0.5,
            "freq": 1
          }
        ]
      }
    ]
  }
}

在term query中,需要的是:not analyzed。即是字段是 keyword类型的,不进行分词处理的字段。

在term suggester中,如何对中文进行处理?说明:上述是安装了ik分词的。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文