Elasticsearch简称ES。git
是一个全文搜索服务器,也可做为NoSQL数据库,存储任意格式的文档和数据,也可作大数据的分析,是一个跨界开源产品。数据库
ES的特色:json
全文搜索引擎浏览器
文档存储和查询服务器
大数据分析网络
提供了REST API,用来简化对ES的操做app
经常配合传统数据库一块儿使用,ES用来负责大数据的查询、搜索、统计分析curl
1.下载elasticsearch
elasticsearch-6.8.3.zip https://www.elastic.co/downloads/past-releases#elasticsearchpost
2.启动
解压 elasticsearch-6.8.3.zip
打开cmd,进入elasticsearch的bin
elasticsearch
9200端口是对外的RESTFul接口,9300端口是ES内部使用的端口
启动后在浏览器 http://localhost:9200/
说明:
name表明这台ES的名字
cluster_name默认名字是elasticsearch。ES的集群方式是经过广播在同一个网络中寻找cluster_name同样的ES
若是想修改配置,能够在config/elasticsearch.yml配置
3.基本概念
Index:是Document的集合,Index包含了Type,至关于数据库
Type:用来进一步组织Document,一个Index能够有多个Type,至关于表
Document:文档,是ES可以存储和搜索的基本信息,Document属于Type,至关于行数据,json格式的
Node:节点,是集群里的一台ES Server,用于Document的存储和查询
Shards:分区,Index超过了单个节点存储的限制,就会将Index进行分区
Replicas:复制分区,将Index分为多个分区,Index的分区为主分区,复制的分区为复制分区
4.基本使用
(1)添加文档
curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap","type":"cleaning","postDate":"2019-9-15","message":"this is a first data"}'
(2)根据主键查询
curl -XGET 'localhost:9200/store/category/1?pretty'
(3)根据主键更新
curl -XPUT 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap123","type":"cleaning","postDate":"2019-9-15T23:10:10","message":"update data"}'
只更新message
curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:applicat ion/json' -d'{"doc":{"message":"only update message"}}'
(4)根据主键删除
curl -XDELETE 'localhost:9200/store/category/1?pretty'
(5)搜索
curl -XPOST 'localhost:9200/store/category/_search?pretty'
全文搜索
curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'
精确搜索
curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"term":{"type":"cleaning"}}}'
查询总数
将_count替换_search
curl -XPOST 'localhost:9200/store/category/_count?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'
联合查询
curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"bool":{"must":[{"term":{"type":"eating"}},{"match":{"message":"second"}}]}}}'
翻页,使用from和size
curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"from":1,"size":1,"query":{"match":{"message":"data"}}}'
说明:
安装了git就会带有curl功能了