elasticsearch 索引操作

RESTful接口格式

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口

URL的格式:http://host:port/index/type/id

  • 其中index、type是必须提供的。
  • id是可选的,不提供es会自动生成。
  • index、type将信息进行分层,利于管理。
  • index可以理解为数据库;type理解为数据表;id相当于数据库表中记录的主键,是唯一的。

常用的HTTP动词

  • GET 请求:获取服务器中的对象
  • POST 请求:在服务器上更新对象
  • PUT 请求:在服务器上创建对象
  • DELETE 请求:删除服务器中的对象
  • HEAD 请求:仅仅用于获取对象的基础信息

  

HTTP客户端

操作REST API常用的有通过CRUL命令,postman等

创建索引

语法:PUT http://host:port/index_name/ + index_configuration

例子

curl -X PUT http://118.195.173.53:9200/user

返回结果

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "user"
}

查询索引

语法:GET http://host:port/index_name

例子

curl -X GET http://118.195.173.53:9200/user

返回结果

{
    "user": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1633772033887",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "RxOy_yAWQ9G3M0dV4Fa4cw",
                "version": {
                    "created": "7070099"
                },
                "provided_name": "user"
            }
        }
    }
}

删除索引

语法:DELETE http://host:port/index_name

例子

curl -X DELETE http://118.195.173.53:9200/user

返回结果

{
    "acknowledged": true
}
posted @ 2021-10-09 18:01  胡勇健  阅读(105)  评论(0)    收藏  举报