数据操作:
增删改查
Elasticsearch核心概念VS数据库核心概念
Elasticsearch 数据库
=========================
Document 行
Type 表
Index 库
filed 字段
插入数据不需要提前创建好数据库
curl -XPUT 192.168.189.118:9200/vipinfo ##创建一个索引,名字叫 vipinfo
curl -XPUT 192.168.189.118:9200/vipinfo1?pretty ##反馈信息比较友好
在谷歌浏览器里面,重新连接ES
默认的集群名称:elasticsearch
集群状态颜色:
绿色: 所有条件都满足,数据完整,副本满足
黄色: 数据完整,副本不满足
红色: 有索引里的数据出现不完整了
紫色: 有分片正在同步中
删除索引:
插入数据:
curl -XPUT '192.168.189.118:9200/vipinfo1/user/1?pretty' -H 'Content-Type: application/json' -d'
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing","interests" : [ "sports", "music" ]
}
'
查询数据:
默认随机生成_ID -- 唯一键ID
curl -XPOST '192.168.189.118:9200/vipinfo1/user/?pretty' -H 'Content-Type: application/json' -d'
{
"first_name" : "scl",
"last_name" : "ysj",
"age" : 23,
"about" : "I love to go rock climbing","interests" : [ "sports", "music" ]
}
'
curl 查询数据:
curl -XGET 192.168.189.118:9200/vipinfo1/stu/_search?pretty
按条件查询:
curl -XGET 192.168.189.118:9200/vipinfo1/user/4?pretty
curl -XGET '192.168.189.118:9200/vipinfo1/user/_search?q=last_name:Fir&pretty'
q-----> 相当于 mysql 里面的 where
用工具查询:
更新数据(两种方式):
## PUT更新,需要填写完整的信息:
把id为1的年龄改为27
curl -XPUT 'http://192.168.189.118:9200/vipinfo1/user/1?pretty' -H 'Content-Type: application/json' -d '
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 27,
"about" : "I love to go rock climbing","interests": ["sports","music"]
}'
## POST更新,只需要填写更改的信息:
curl -XPOST 'http://192.168.189.118:9200/vipinfo1/user/1?pretty' -H 'Content-Type: application/json' -d '
{
"age" : 29
}'
更新数据,保险还是用PUT
+++++++++++++ 用工具更新数据:
删除指定文档数据:
curl -XDELETE 'http://192.168.189.118:9200/vipinfo1/user/1?pretty'
删除整个索引:
curl -XDELETE 'http://192.168.189.118:9200/abc?pretty'