环境:elasticsearch7.8.0 + Postman
Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。
索引操作
1、创建索引
method:PUT
url:
http://localhost:9200/users
body:可选
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 0
}
}
number_of_shards:分片数量
number_of_replicas:副本数量
2、查看全部索引
method:GET
URL:
http://localhost:9200/_cat/indices?v
3、查看单个索引
method:GET
url:
http://localhost:9200/users
4、删除索引
method:DELETE
url:
http://localhost:9200/users
文档操作
1、创建文档
method:POST
url:
http://localhost:9200/users/_doc
body:
{"name":"张三", "sex":"男", "age":30}
2、创建文档(指定唯一标识)
method:POST
url:
http://localhost:9200/student/_doc/唯一ID
body:
{"name":"莉莉", "sex":"女","age":30}
3、查看文档
method:GET
url:
http://localhost:9200/users/_doc/唯一ID
4、修改文档
method:POST
url:
http://localhost:9200/users/_doc/唯一ID
body:
{"name":"莉莉007", "sex":"女","age":60}
5、修改文档(字段)
method:POST
url:
http://localhost:9200/users/_update/唯一ID
body:
{
"doc": {
"age":50
}
}
6、删除文档
method:DELETE
url:
http://localhost:9200/users/_doc/唯一ID
7、根据条件删除文档
method:POST
url:
http://localhost:9200/users/_delete_by_query
body:
{
"query": {
"match": {
"age": 50
}
}
}
创建映射
1、创建映射
method:PUT
url:
http://localhost:9200/users/_mapping
body:
{
"properties": {
"name": {
"type": "text",
"index": true
},
"sex": {
"type": "text",
"index": true
},
"age": {
"type": "long",
"index": true
}
}
}
2、查看映射
method:GET
url:
http://localhost:9200/users/_mapping
完毕!!!
下一篇将会介绍ES高级查询RESTful接口的使用
给个关注+转发呗谢谢