Chinaunix首页 | 论坛 | 博客
  • 博客访问: 690456
  • 博文数量: 26
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 3182
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-23 14:29
个人简介

7年游戏服务器开发,擅长c/c++,javesript,php;熟悉linux,mysql/redis,elasticsearch;开源爱好者.github : https://github.com/yuyunliuhen

文章分类

全部博文(26)

文章存档

2016年(1)

2015年(3)

2014年(3)

2013年(19)

分类: 大数据

2015-11-25 18:11:47

 废话不多说,三步走:mapping->index->search.

点击(此处)折叠或打开

  1. curl -XDELETE ''
  2. curl -XPUT ''
  3. curl -XPUT "_mapping/test" -d'
  4. {
  5.     "test": {
  6.         "properties" : {
  7.             "suggest" : {
  8.                 "type" : "completion",
  9.                 "index_analyzer" : "simple",
  10.                 "search_analyzer" : "simple"
  11.             }
  12.         }
  13.     }
  14. }'

  15. curl -XPUT http://localhost:9200/sug/test/1 -d '{
  16.     "suggest":{
  17.         "input":["李一","ly","liyi"],
  18.         "output":"李一"
  19.     }
  20. }'

  21. curl -XPUT test/2 -d '{
  22.     "suggest":{
  23.         "input":["李二","lr","lier"],
  24.         "output":"李二"
  25.     }
  26. }'

  27. curl -XPUT test/3 -d '{
  28.     "suggest":{
  29.         "input":["张三","zs","zhangsan"],
  30.         "output":"张三"
  31.     }
  32. }'

  33. curl -XPOST _suggest?pretty -d '{
  34.   "index-suggest" : {
  35.     "text" : "李",
  36.     "completion" : {
  37.       "offset": 0,
  38.       "size": 9,
  39.       "field" : "suggest"
  40.     }
  41.   }
  42. }'

  43. curl -XPOST _suggest?pretty -d '{
  44.   "index-suggest" : {
  45.     "text" : "ly",
  46.     "completion" : {
  47.       "offset": 0,
  48.       "size": 9,
  49.       "field" : "suggest"
  50.     }
  51.   }
  52. }'

  53. curl -XPOST _suggest?pretty -d '{
  54.   "index-suggest" : {
  55.     "text" : "l",
  56.     "completion" : {
  57.       "offset": 0,
  58.       "size": 9,
  59.       "field" : "suggest"
  60.     }
  61.   }
  62. }
效果展示:


阅读(2407) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~