(1).在elasticsearch-head插件手工创建索引,索引名称learn,索引相当于数据库
(2).创建类型,并设置类型的mapping,相当于创建表,并设置表结构
类型为video相当于表,mapping相当于为表设置结构
请求地址:http://localhost:9200/learn/
请求方式:PUT
请求内容:
{
"mappings": {
"video": {
"properties": {
"name": {
"type": "text"
},
"cat_id": {
"type": "integer"
},
"image": {
"type": "text"
},
"url": {
"type": "text"
},
"type": {
"type": "byte"
},
"content": {
"type": "text"
},
"uploader": {
"type": "keyword"
},
"create_time": {
"type": "integer"
},
"update_time": {
"type": "integer"
},
"status": {
"type": "byte"
},
"video_id": {
"type": "keyword"
}
}
}
}
}其实我们不设置mapping,es也会自动检测文档类型设置maping
(3).索引一个文档记录,手动指定记录id,相当于新增记录
请求地址:http://localhost:9200/learn/video/1/
请求方式:PUT
请求内容:
{
"name":"林芳臻",
"cat_id":1,
"image":"http://www.gaojiufeng.cn/a.png",
"url":"http://www.gaojiufeng.cn/a.html",
"type":1,
"uploader":"gao",
"status":1,
"video_id":"linfangzhen"
}记录id为1,如果我们是想把mysql的数据同步到es中,那么我们自己传递id很有必要
(4).索引一个文档记录,使用es自动生成id,相当于新增记录
请求地址:http://localhost:9200/learn/video/
请求方式:POST
请求内容:
{
"name":"林芳臻3",
"cat_id":1,
"image":"http://www.gaojiufeng.cn/a.png",
"url":"http://www.gaojiufeng.cn/a.html",
"type":1,
"uploader":"gao",
"status":1,
"video_id":"linfangzhen"
}记录id为0eeyRnIBO2vtaZYtd_La
(5).查询一个文档记录,关键字分词查询
请求地址:http://localhost:9200/learn/video/
请求操作:_search
请求方式:POST
请求内容:
{
"query":{
"match":{
"name":"林芳臻"
}
}
}返回结果:
{
"took":12,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":3,
"max_score":0.5809142,
"hits":[
{
"_index":"learn",
"_type":"video",
"_id":"2",
"_score":0.5809142,
"_source":{
"name":"林芳臻",
"cat_id":1,
"image":"http://www.gaojiufeng.cn/a.png",
"url":"http://www.gaojiufeng.cn/a.html",
"type":1,
"uploader":"gao",
"status":1,
"video_id":"linfangzhen"
}
},
{
"_index":"learn",
"_type":"video",
"_id":"0eeyRnIBO2vtaZYtd_La",
"_score":0.51676416,
"_source":{
"name":"林芳臻3",
"cat_id":1,
"image":"http://www.gaojiufeng.cn/a.png",
"url":"http://www.gaojiufeng.cn/a.html",
"type":1,
"uploader":"gao",
"status":1,
"video_id":"linfangzhen"
}
},
{
"_index":"learn",
"_type":"video",
"_id":"1",
"_score":0.2876821,
"_source":{
"name":"臻子",
"cat_id":1,
"image":"http://www.gaojiufeng.cn/a.png",
"url":"http://www.gaojiufeng.cn/a.html",
"type":1,
"uploader":"gao",
"status":1,
"video_id":"linfangzhen"
}
}
]
}
}搜索的结果中不仅仅包含林芳臻,还包含臻子,说明es中使用match搜索会对关键词进行分词查询,林芳臻被分为“林”,“芳”,“臻”3个字来查询,但是可以看到每个结果得到的匹配分数是不同的。但是有的时候我们只是想搜索包含林芳臻的结果,该怎么搜索,请看下面。
(6).查询一个文档记录,关键字不分词查询
请求地址:http://localhost:9200/learn/video/
请求操作:_search
请求方式:POST
请求内容:
{
"query":{
"match_phrase":{
"name":"林芳臻"
}
}
}返回结果:
{"took": 128,
"timed_out": false,
"_shards": {},
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
"hits": {}
{}
,
{}
"name": "林芳臻",
"cat_id": 1,
"image": "http://www.gaojiufeng.cn/a.png",
"url": "http://www.gaojiufeng.cn/a.html",
"type": 1,
"uploader": "gao",
"status": 1,
"video_id": "linfangzhen"
"_index": "learn",
"_type": "video",
"_id": "2",
"_score": 0.5809142,
"_source": {}
"name": "林芳臻3",
"cat_id": 1,
"image": "http://www.gaojiufeng.cn/a.png",
"url": "http://www.gaojiufeng.cn/a.html",
"type": 1,
"uploader": "gao",
"status": 1,
"video_id": "linfangzhen"
"_index": "learn",
"_type": "video",
"_id": "0eeyRnIBO2vtaZYtd_La",
"_score": 0.5167642,
"_source": {}
"total": 2,
"max_score": 0.5809142,
"hits": []
}使用match_phrase匹配到的结果只会包含关键字
(7).查询一个文档,自定义聚合数据,类似于group,比如统计每个分类cat_id下有多少条数据
请求地址:http://localhost:9200/learn/video/
请求操作:_search
请求方式:POST
请求内容:
{
"aggs":{
"id_result":{
"terms":{
"field":"cat_id"
}
}
}
}返回结果:
{
"aggregations":{
"id_result":{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":0,
"buckets":[
{
"key":1,
"doc_count":3
},
{
"key":2,
"doc_count":1
}
]
}
}
}统计出cat_id分类有2个分类,分别为catid1和2,并且统计文档数量
在安装之前我们先看看官方给出的依赖关系.首先是dll文件和mongodb软件的依赖关系然后是PHP文件和dll的依赖关系我的是phpstudy的集成环境PHP5.4.45 NTS+Apache+Mysql【一】.安装mongodb3.0软件对比依赖关系下载mongodb3.0.msi软件,完整名称:...
1.关机Process.Start("shutdown", "-s -t 0"); 2. 注销 Proc...
首先在阿里云申请免费的证书,选择自动生成证书。然后就是nginx虚拟主机配置文件的修改。以下是我的配置文件(因为公司开发小程序,没有办法只能使用https)。您只需要关注带有ssl的配置选项,我增加了一个监听80和443的端口,同时增加了http跳转https的配置server &nbs...
vsftp常用操作命令:1.启动vsftp: service vsftpd start 2.重启vsftp: service vsftpd restart3.修改用户密码:passwd lao8org4.创建用户:useradd -d /data/wwwroot/blog -s /sbin...
1.set key value [ex 秒数] / [px 毫秒数] [nx] /[xx]如: set a 1 ex 10 , 10秒有效Set a 1 px 9000 , 9秒有效注: 如果ex,px同时写,以后面的有效期为准如 set a 1 ex 100 px 9000...
1.lpush key value 作用: 把值插入到链接头部(左边)2.rpush key value 作用: 把值插入到链接尾部(右边)3.lrange key start stop 作用: 返回链表中[start ,stop]中的元素 规律: 左数从0开始,...