1、elasticsearch的基本介绍
原理和概念介绍
参考csdn https://blog.csdn.net/zhenwei1994/article/details/94013059
基础原理和使用
参考csdn https://blog.csdn.net/qq_38262266/article/details/90311086
es的学习教程
https://blog.csdn.net/laoyang360/article/details/52244917?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
Elasticsearch的文件存储
Elasticsearch是面向文档型数据库,一条数据在这里就是一个文档,用JSON作为文档序列化的格式
关系数据库 ⇒ 数据库 ⇒ 表 ⇒ 行 ⇒ 列(Columns)
Elasticsearch ⇒ 索引(Index) ⇒ 类型(type) ⇒ 文档(Docments) ⇒ 字段(Fields)
一个 Elasticsearch 集群可以包含多个索引(数据库),也就是说其中包含了很多类型(表)。这些类型中包含了很多的文档(行),然后每个文档中又包含了很多的字段(列)。
Elasticsearch的交互,可以使用Java API,也可以直接使用HTTP的Restful API方式
2、elasticsearch的官方文档
https://www.elastic.co/cn/elasticsearch/
3、elasticsearch的增删改查
ES Restful API GET、POST、PUT、DELETE、HEAD含义:
1)GET:获取请求对象的当前状态。
2)POST:改变对象的当前状态。
3)PUT:创建一个对象。
4)DELETE:销毁对象。
5)HEAD:请求获取对象的基础信息。
(1)、新建文档(类似mysql insert插入操作)
http://localhost:9200/blog/ariticle/1 put
{
“title”:“New version of Elasticsearch released!”,
“content”:“Version 1.0 released today!”,
“tags”:[“announce”,“elasticsearch”,“release”]
}
{
- “_index”: “blog”,
- “_type”: “ariticle”,
- “_id”: “1 -d”,
- “_version”: 1,
- “_shards”: {
- “total”: 2,
- “successful”: 1,
- “failed”: 0
- },
- “created”: true
}
_id ?代表文档?
_version ?
_shards ?
created 代表新建
(2)、检索文档(类似mysql search 搜索select*操作)
http://localhost:9200/blog/ariticle/1/ GET
{
- “_index”: “blog”,
- “_type”: “ariticle”,
- “_id”: “1”,
- “_version”: 1,
- “found”: true,
- “_source”: {
- “title”: “New version of Elasticsearch released!”,
- “content”: “Version 1.0 released today!”,
- “tags”: [
- “announce”
- ,
- “elasticsearch”
- ,
- “release”
- ]
- }
}
found 查询发现
_source 代表查询的行数据?
没找到
{
- “_index”: “blog”,
- “_type”: “ariticle”,
- “_id”: “11”,
- “found”: false
}
_id ?
查询举例1:查询cotent列包含版本为1.0的信息。
http://localhost:9200/blog/
_search?pretty&q=content:1.0
{
- “took”: 2,
- “timed_out”: false,
- “_shards”: {
- “total”: 5,
- “successful”: 5,
- “failed”: 0
- },
- “hits”: {
- “total”: 1,
- “max_score”: 0.8784157,
- “hits”: [
- {
- “_index”: “blog”,
- “_type”: “ariticle”,
- “_id”: “6”,
- “_score”: 0.8784157,
- “_source”: {
- “title”: “deep Elasticsearch!”,
- “content”: “Version 1.0!”,
- “tags”: [
- “deep”
- ,
- “elasticsearch”
- ]
- }
- }
- {
- ]
- }
}
pretty ?
took ?
_shards 分片
hits ?
(3)、更新文档(类似mysql update操作)
http://localhost:9200/blog/ariticle/1/_update/ POST
{“script”:”ctx._source.content = \”new version 2.0 20160714\”“}
更新后结果显示:
{
“_index”: “blog”,
“_type”: “ariticle”,
“_id”: “1”,
“_version”: 2,
“_shards”: {
”total”: 2,
“successful”: 1,
“failed”: 0
}
}
http://localhost:9200/blog/ariticle/1/_update/ POST
{“script”:”ctx._source.content = \”new version 2.0 20160714\”“}
更新后结果显示:
{
“_index”: “blog”,
“_type”: “ariticle”,
“_id”: “1”,
“_version”: 2,
“_shards”: {
”total”: 2,
“successful”: 1,
“failed”: 0
}
}
“script” ?
(4)、删除文档(类似mysql delete操作)
http://localhost:9200/blog/ariticle/8/回结果
{
- “found”: true,
- “_index”: “blog”,
- “_type”: “ariticle”,
- “_id”: “8”,
- “_version”: 2,
- “_shards”: {
- “total”: 2,
- “successful”: 1,
- “failed”: 0
- }
}
4、es与springboot的整合
- shards:分片数量,默认5
- replicas:副本数量,默认1