PUT s15 { "mappings": { "properties": { "title": { "type": "completion" } } } } # 添加数据的几种形式 PUT s15/_doc/1 { "title":{ "input": "blow", "weight": 2 } } PUT s15/_doc/2 { "title":{ "input": "block", "weight": 3 # 建议 权重 } } PUT s15/_doc/4 { "title": { "input": "beock", "weight": 3 } } PUT s15/_doc/3 { "title": [ # 添加多条数据 { "input": "blong", "weight": 20 }, { "input": "blockk", "weight": 30 } ] } GET s15/_search { "suggest": { "my_s4": { "text": "blo", "completion": { "field": "title" } } } } GET s15/_search { "suggest": { "my_s5": { "text": "blo", "completion": { "field": "title" } } } } GET s15/_search { "suggest": { "my_s6": { "text": "blaw", "completion": { "field": "title", "size": 5, "skip_duplicates": true, "fuzzy": { # 模糊查找 建议 "fuzziness": 3, "min_length": 3, # 最小长度 "prefix_length": 2 # 最左边第几个字符开始模糊查找 } } } } , "_source": "title" # 返回指定字段 } GET s15/_search { "suggest": { "my_s7": { "regex": "b[l|e]o", # 正则匹配建议 "completion": { "field": "title" } } } }