Elasticsearch RESTful API Request explanation

Source: Internet
Author: User

可以使用行命令 curl 通过9200端口与 Elasticsearch 的 RESTful API 进行通信。

 

Elasticsearch RESTful API规范

例如,计算集群中文件的数量,我们就可以使用:

      <1>     <2>                   <3>    <4>

curl -XGET ‘http://localhost:9200/_count?pretty‘-d ‘

{  <5>

    "query": {

        "match_all": {}

    }

}

详细说明:

1.相应的 HTTP 请求方法 或者 变量 : GET, POST, PUT, HEAD 或者 DELETE。

2.集群中任意一个节点的访问协议、主机名以及端口。

3.请求的路径。

4.任意一个查询后再加上 ?pretty 就可以生成 更加美观 的JSON反馈,以增强可读性。

5.一个 JSON 编码的请求主体(如果需要的话)。

 

Elasticsearch将会返回一个 HTTP 状态码类似于 ‘200 OK‘,以及一个 JSON 格式的主体(除了单纯的 ‘HEAD‘ 请求),上面的请求会得到下方的 JSON 主体:

 

{

    "count" : 0,

    "_shards" : {

        "total" : 5,

        "successful" : 5,

        "failed" : 0

    }

}

在反馈中,我们并没有看见 HTTP 的头部信息,因为我们没有告知 curl 显示这些内容。

 

如果你想看到头部信息,可以在使用 curl 命令的时候再加上 -i 这个参数:

curl -i -XGET‘localhost:9200/‘

 

从现在开始,本书里所有涉及 curl 命令的部分我们都会进行简写,因为主机、端口等信息都是相同的,缩减前的样子:

 

curl -XGET‘localhost:9200/_count?pretty‘ -d ‘

{

    "query": {

        "match_all": {}

    }

}‘

我们将会简写成这样:

 

GET /_count

{

    "query": {

        "match_all": {}

    }

}

This article is from the "Cexpert" blog, make sure to keep this source http://cexpert.blog.51cto.com/5251990/1833407

Elasticsearch RESTful API Request explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.