ElasticSearch RESTful接口详细说明(一)

导读:本篇文章讲解 ElasticSearch RESTful接口详细说明(一),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

环境: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:副本数量

ElasticSearch RESTful接口详细说明(一)

 

2、查看全部索引
method:GET
URL:
http://localhost:9200/_cat/indices?v

ElasticSearch RESTful接口详细说明(一)

 

3、查看单个索引
method:GET
url:
http://localhost:9200/users

ElasticSearch RESTful接口详细说明(一)

 

4、删除索引
method:DELETE
url:
http://localhost:9200/users

ElasticSearch RESTful接口详细说明(一)

 

文档操作

1、创建文档
method:POST
url:
http://localhost:9200/users/_doc
body:

{"name":"张三", "sex":"男", "age":30}

ElasticSearch RESTful接口详细说明(一)

 

2、创建文档(指定唯一标识)
method:POST
url:
http://localhost:9200/student/_doc/唯一ID
body:

{"name":"莉莉", "sex":"女","age":30}

ElasticSearch RESTful接口详细说明(一)

 

3、查看文档
method:GET
url:
http://localhost:9200/users/_doc/唯一ID

ElasticSearch RESTful接口详细说明(一)

 

4、修改文档
method:POST
url:
http://localhost:9200/users/_doc/唯一ID
body:

{"name":"莉莉007", "sex":"女","age":60}

ElasticSearch RESTful接口详细说明(一)

 

5、修改文档(字段)
method:POST
url:
http://localhost:9200/users/_update/唯一ID
body:

{
  "doc": {
    "age":50
  }
}

ElasticSearch RESTful接口详细说明(一)

 

6、删除文档
method:DELETE
url:
http://localhost:9200/users/_doc/唯一ID

ElasticSearch RESTful接口详细说明(一)

 

7、根据条件删除文档
method:POST
url:
http://localhost:9200/users/_delete_by_query
body:

{
  "query": {
    "match": {
      "age": 50
    }
  }
}

ElasticSearch RESTful接口详细说明(一)

 

创建映射

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
    }
  }
}

ElasticSearch RESTful接口详细说明(一)

 

2、查看映射
method:GET
url:
http://localhost:9200/users/_mapping

ElasticSearch RESTful接口详细说明(一)

 

完毕!!!

下一篇将会介绍ES高级查询RESTful接口的使用

给个关注+转发呗谢谢

ElasticSearch RESTful接口详细说明(一)

ElasticSearch RESTful接口详细说明(一)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/80026.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!