自动补全(中文)
定义索引
1 | [root@icloud-store ~]# curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true" -H 'Content-Type: application/json' -d' |
定义类型
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/product/_mapping?pretty=true" -H 'Content-Type: application/json' -d' |
查看索引
1 | [root@icloud-store ~]# curl -XGET "http://192.168.0.103:9200/index_test?pretty=true" |
索引数据
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/product/1?pretty=true" -H 'Content-Type: application/json' -d'{ |
搜索示例
简单自动补全示例
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
指定返回特定列
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
模糊搜索
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
指定推荐数量
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
拼音搜索推荐
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
可以看到拼音搜索并不能得到友好的推荐词,所以需要结合拼音分词进行再一次优化.
自动补全(中文+拼音)
删除索引
1 | [root@icloud-store ~]# curl -XDELETE "http://192.168.0.103:9200/index_test*?pretty=true" |
定义索引
1 | [elon@icloud-store elasticsearch-6.0.0]$ curl -XPUT "http://192.168.0.103:9200/index_test?pretty=true" -H 'Content-Type: application/json' -d' |
定义类型
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/product/_mapping?pretty=true" -H 'Content-Type: application/json' -d' |
创建索引
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/product/1?pretty=true" -H 'Content-Type: application/json' -d'{ |
补全搜索(拼音)
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |
模糊搜索(拼音)
1 | [root@icloud-store ~]# curl -XPOST "http://192.168.0.103:9200/index_test/_search?pretty" -H 'Content-Type: application/json' -d' |