1.Elasticsearch简介
1.1
分布式全文搜索引擎
1.2
倒排序索引:关键字--id--数据(传统索引:id--数据)。
创建文档:建立数据关系(每一条数据)。
使用文档:输入关键字找到文档。
2.启动ES
启动成功
3.添加分词器ik,重新启动ES
4.利用postman创建索引(json格式与ES的版本有关 ES6.5.4)
JSON格式化高亮工具 - 在线JSON校验格式化工具(K JSON)
{
"mappings": {
"book": {
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"copy_to": "all"
},
"type": {
"type": "keyword"
},
"description": {
"type": "text",
"analyzer": "ik_max_word",
"copy_to": "all"
},
"all": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
5.创建文档
创建文档的时候ES一直报错,不能有type类型。
{
"name":"小花",
"description":"我是一个听话的孩子"
}
post http://localhost:9200/students/_doc 使用系统生成的id
post http://localhost:9200/students/_doc/4 使用指定id,不存在创建,存在更新(版本递增)
post http://localhost:9200/students/_create/4 使用指定id
6.查询文档
get http://localhost:9200/students/_doc/4 查询单个文档
get http://localhost:9200/students/_search 查询全部文档
get http://localhost:9200/students/_search?q=decription:'"听话" 查询全部文档
7.删除文档
delete http://localhost:9200/students/_doc/4
8.修改文档
8.1全量修改
put http://localhost:9200/students/_doc/2
{
"name":"小明",
"description":"我是一个听话的孩子"
}
8.2部分修改
post http://localhost:9200/students/_doc/2/_update?pretty ES版本6.5.4.
post http://localhost:9200/students/_update/2 ES版本 7.16.2
{
"doc":{
"name":"哎呦"
}
}