一.ES的介绍
1.基本概念
分布式全文搜索引擎
2.特点
1.基于lucene
2.使用简单
3.分布式的 ,
4.基于Restful API(http),
5.支持各种客户端(java,php。。)
6.PB级别数据
7.性能好,速度高(近实时)
8.支持集群
9.ES处理JSON格式的数据
二.安装ES
1.安装ES
2.kibana(elasticsearch-head)
三.回顾Restful
1.定义
使用名词表示资源,使用动词表示操作
2.简单案例
四.ES相关概念
1.近实时
2.索引库 index -> 数据库
3.文档类型 type -> 表
4.文档 document -> 表中的一行一行数据
5.列 field -> 一个document由多个列组成 -> 表中的列
6.集群 -> 包括了多个node(一个es,一台电脑) ,默认名字“elasticsearch”
7.节点 node /一个主机/一个ES -> node 默认启动会加入名字叫 “elasticsearch”的集群
8.shard : 分片 , 一个索引库被分成多个分片,多个分片分散在不同的 node上 -> 像数据库的分库
9.replica : 复制品(从/备) , shard分为 parmary shard 主分片, replica备分片 ,
一个主shard和它的备shard不能再一个node上 , 非一对主shard和备shard是可以在一个node上
主shard数量不能修改 ,备shard的数量可以修改
五.文档的CRUD
添加
PUT /索引库/文档类型/文档id
{
json格式的文档内容
}
全局修改
POST /索引库/文档类型/文档id
{
json格式的文档内容
}
局部修改
POST /索引库/文档类型/文档id/_update
{
“doc”:{
json格式的文档内容
}
}
删除文档
DELETE /索引库/文档类型/文档id
获取文档
GET /索引库/文档类型/文档id
批量获取
GET _mget
{
“docs”:[
{"_index":“crm”, “_type”:“user”},
{}
]
}
六.文档简单查询
GET _search 查询所有
GET /索引库/文档类型/_search?q=name:zs&form=10&size=10
七.DSL查询
GET itsource/employee/_search
{
“query”: {
“match_all”: {}
},
“from”: 20,
“size”: 10,
“_source”: [“fullName”, “age”, “email”],
“sort”: [{“join_date”: “desc”},{“age”: “asc”}]
}
八.DSL过滤
GET itsource/employee/_search
{
“query”: {
“bool”: { //boolQuery 组合查询
// 与(must) 或(should) 非(must not)
"must": [
{
"match": { //matchQuery -> 分词匹配 有点像 like
"name": "hello world"
}
} ,
{"match": {"description": "search" }}
],
"filter": {
"term": { //termQuery -> 单词查询
“username”: “haha zs” //精确匹配
}
}
}
},
“from”: 20,
“size”: 10,
“_source”: [“fullName”, “age”, “email”],
“sort”: [{“join_date”: “desc”},{“age”: “asc”}]
}
1.标准查询 : match
2.单词查询:term
3.组合查询:bool
4.范围查询:range
5.是否存在: exists 和 missing
6.前缀匹配:prefix
7.通配符: wildcard ,使用 * 多个,?一个
十.映射
1.基本字段类型
字符串: text (分词), keyword(不分词)