elasticsearch入门,linux上简单操作
2017-11-01 18:03
471 查看
福利:
入门视频点击此处,注册账号看前几章,入门还是没问题的
入门操作:
说明:我这里新建的名称—index为test,type为kind
1、创建索引
入门视频点击此处,注册账号看前几章,入门还是没问题的
入门操作:
说明:我这里新建的名称—index为test,type为kind
1、创建索引
curl -XPUT http://localhost:9200/test[/code] 补充,更详尽教程详见:java创建索引、linux创建
相应的删除索引:curl -XDELETE http://localhost:9200/test[/code]
2、创建restful风格插入
curl -XPOST http://localhost:9200/索引名称/索引类型/id -d JSON格式的参数curl -XPUT http://localhost:9200/test/kind/1?pretty -d '{"title":"test_1","label":["sofa","beauty","white","American"],"create_date":"2017-11-1 15:41"}'
注意:这种方式插入,中文会报错(我就因为这问题,耽误半天)
入门实验操作:
首先——插入几条测试数据:curl -XPUT http://localhost:9200/test/kind/1?pretty -d '{"title":"sofa_1","label":["sofa","beauty","white","American"],"create_date":"2017-11-1 15:41"}' curl -XPUT http://localhost:9200/test/kind/2?pretty -d '{"title":"sofa_2","label":["sofa","beauty","red","American"],"create_date":"2017-11-1 14:41"}' curl -XPUT http://localhost:9200/test/kind/3?pretty -d '{"title":"sofa_3","label":["sofa","cute","red","China"],"create_date":"2017-11-1 13:41"}' curl -XPUT http://localhost:9200/test/kind/4?pretty -d '{"title":"chair_4","label":["chair","cute","red","China"],"create_date":"2017-11-1 12:41"}' curl -XPUT http://localhost:9200/test/kind/5?pretty -d '{"title":"chair_5","label":["chair","beauty","white","American"],"create_date":"2017-11-1 11:41"}' curl -XPUT http://localhost:9200/test/kind/6?pretty -d '{"title":"chair_6","label":["chair","beauty","black","China"],"create_date":"2017-11-1 10:41"}'
①、搜索lable中含有China的curl http://localhost:9200/test/kind/_search?q=label:China[/code]
②、搜索label中含有“beauty American”相关内容
(测试结果:这里返回内容就类似搜索引擎,匹配度越高优先返回,但也有些不是这样:比如搜"white American")curl -X GET http://localhost:9200/test/kind/_search?pretty -d '{"query" : {"match" : {"label" : "beauty American"}}}'
便于阅读,格式化如下:curl http://localhost:9200/test/kind/_search?pretty -d '{ "query" : { "match" : { "label" : "beauty American" } } }'
③、在满足2的基础上,再按照标签出现的次数推荐标签curl -X GET http://localhost:9200/test/kind/_search?pretty -d '{"query" : {"match" : {"label" : "beauty American"}},"aggs": {"all_label": {"terms": { "field": "label" }}}}'
注意:这里使用elasticsearch的aggregations聚合查询有个问题,中文会被拆分成单个字统计,要将字段设置属性:
感谢文章:http://jingyan.baidu.com/article/15622f2400c160fdfcbea5e9.html
curl -X PUT http://localhost:9200/test/_mapping/kind/ -d '{"properties": {"label": {"type":"text","index": "not_analyzed"}}}'
警告:这里会报一个错误,点击:Fielddata is disabled on text fields by default
错误解决办法:执行如下操作,注意添加"_mapping",感觉这句相当于给label字段定义为text类型,设置fielddata为true:
curl -X PUT http://localhost:9200/test/_mapping/kind/ -d '{"properties": {"label": {"type":"text","index":
"not_analyzed","fielddata":
true}}}'
相关文章推荐
- linux下git的简单操作(入门)
- linux入门1-简单命令操作
- Linux入门——vim编辑器简单操作
- Linux 学习--简单命令入门文件操作命令
- linux入门第二讲、一些命令、命令历史和一些简单的操作
- linux => Ubuntu 安装mysql和简单操作
- linux驱动开发:用户空间操作LCD显示简单的图片
- .NET 操作MongoDB入门(三)最简单的增删改查操作
- PostgreSQL 数据操作入门,简单对比MySQL
- linux-ubuntu 简单优盘操作
- Linux文件简单了解及文件的创建操作操作
- MongoDB快速入门笔记(二)之MongoDB的概念及简单操作
- Linux简单入门(一)
- Linux常用操作命令——FireFly入门视频教程02
- 3、Linux程序设计入门--文件操作
- ElasticSearch 简单入门
- 3、linux文件夹简单操作和光盘挂载
- linux下vi的一些简单的操作
- linux程序调试命令addr2line之入门简单介绍(本文先不聊gdb调试)
- 简单文件操作 linux