elasticsearch term suggester 中文
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论