elasticsearch用的版本是6.2,我们准备做搜索提示,遇到了一个问题,用户可能会输入中文,英文,拼音,所以,我们给提示的字段用了不同的分词,但是,现在提示的时候,只能用在一个分词上,怎么才能用在多个分词上?
自定义分词:
搜索:
如上所示,field字段只能写一个,而我还想用body.pinyin,body.english该怎么写呢?
自定义分词:
PUT /dev_suggest
{
"settings": {
"analysis": {
"filter": {
"pinyin_simple_filter": {
"lowercase": "true",
"keep_original": "false",
"keep_first_letter": "true",
"keep_separate_first_letter": "false",
"type": "pinyin",
"limit_first_letter_length": "50",
"keep_full_pinyin": "false"
},
"pinyin_full_filter": {
"remove_duplicated_term": "true",
"keep_joined_full_pinyin": "true",
"none_chinese_pinyin_tokenize": "false",
"type": "pinyin",
"keep_none_chinese_in_joined_full_pinyin": "true",
"keep_full_pinyin": "false"
},
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "50"
}
},
"char_filter": {
"stconvert": {
"convert_type": "s2t",
"type": "stconvert",
"keep_both": "true",
"delimiter": "#"
},
"tsconvert": {
"convert_type": "t2s",
"type": "stconvert",
"keep_both": "true",
"delimiter": "#"
},
"charconvert": {
"type": "mapping",
"mappings_path": "char_filter_text.txt"
}
},
"analyzer": {
"ikcnIndexAnalyzer": {
"type": "custom",
"char_filter": [
"charconvert",
"tsconvert"
],
"tokenizer": "ik_max_word"
},
"standardAnalyzer": {
"type": "custom",
"char_filter": [
"charconvert",
"tsconvert"
],
"tokenizer": "standard"
},
"pinyiFullIndexAnalyzer": {
"filter": [
"pinyin_full_filter",
"lowercase"
],
"tokenizer": "my_ngram"
},
"pinyiSimpleIndexAnalyzer": {
"filter": [
"pinyin_simple_filter",
"edge_ngram_filter",
"lowercase"
],
"tokenizer": "keyword"
},
"pinyiFullSearchAnalyzer": {
"filter": [
"pinyin_full_filter",
"lowercase"
],
"tokenizer": "my_ngram"
},
"ikSearchAnalyzer": {
"type": "custom",
"char_filter": [
"charconvert"
],
"tokenizer": "ik_max_word"
},
"iktwIndexAnalyzer": {
"type": "custom",
"char_filter": [
"charconvert",
"stconvert"
],
"tokenizer": "ik_max_word"
},
"ngramIndexAnalyzer": {
"filter": [
"edge_ngram_filter",
"lowercase"
],
"char_filter": [
"charconvert"
],
"type": "custom",
"tokenizer": "keyword"
},
"ngramSearchAnalyzer": {
"filter": [
"lowercase"
],
"char_filter": [
"charconvert"
],
"type": "custom",
"tokenizer": "keyword"
},
"pinyiSimpleSearchAnalyzer": {
"filter": [
"pinyin_simple_filter",
"lowercase"
],
"tokenizer": "keyword"
}
},
"tokenizer": {
"ik_max_word": {
"type": "ik_max_word",
"use_smart": "true"
},
"my_ngram": {
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
],
"type": "ngram"
}
}
}
},
"mappings": {
"doc": {
"properties": {
"body": {
"type": "completion",
"analyzer": "standardAnalyzer",
"fields": {
"pinyin": {
"type": "completion",
"analyzer": "pinyiFullIndexAnalyzer"
},
"english": {
"type": "completion",
"analyzer": "english"
}
}
}
}
}
}
}
搜索:
POST dev_suggest/_search?pretty{
"suggest": {
"song-suggest" : {
"prefix" : "牛肉",
"completion" : {
"field" : "body"
}
}
}
}
如上所示,field字段只能写一个,而我还想用body.pinyin,body.english该怎么写呢?
3 个回复
rochy - rochy_he
赞同来自: newairisme
bellengao - 博客: https://www.jianshu.com/u/e0088e3e2127
赞同来自:
POST music1/_search?pretty
{
"suggest": {
"song-suggest" : {
"prefix" : "ni",
"completion" : {
"field" : "suggest"
}
},
"song1-suggest" : {
"prefix" : "nu",
"completion" : {
"field" : "suggest1"
}
}
}
}
HelloClyde
赞同来自: