1,创建mapping:PUT /news_website { "mappings": { "news" : { "properties" : { "title" : { "type": "text", "analyzer": "ik_max_word", "fields": { "suggest" : { "type" : "completion", "analyzer": "ik_max_word" } } }, "content": { "type": "text", "analyzer": "ik_max_word" } } } } }
2,向索引中写入数据
PUT /news_website/news/1 { "title": "大话西游电影", "content": "大话西游的电影时隔20年即将在2017年4月重映" } PUT /news_website/news/2 { "title": "大话西游小说", "content": "某知名网络小说作家已经完成了大话西游同名小说的出版" } PUT /news_website/news/3 { "title": "大话西游手游", "content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中" }
3,suggest 查询
GET /news_website2/news/_search { "suggest":{ "suggest":{ "prefix":"大话西游", "completion":{ "field":"title.suggest" } } } }
来源:博客园
作者:wangchuanfu
链接:https://www.cnblogs.com/wangchuanfu/p/11558340.html