Elasticsearch api

After installing Es in the previous chapter, try to connect to ES

1. RESTful API using JSON as data interaction format

    Open the terminal and enter the command: curl 'http://localhost:9300/?pretty' , you can see the relevant information of es

{
  "name" : "vQClE4C",
  "cluster_name" : "elasticsearch_myname",
  "cluster_uuid" : "ImC6_BY5SQmksk6KMQHOMA",
  "version" : {
    "number" : "6.0.0",
    "build_hash" : "8f0685b",
    "build_date" : "2017-11-10T18:41:22.859Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

    Command format: refer to https://es.xiaoleilu.com/010_Intro/15_API.html

     

curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'
  • VERB HTTP method: GETPOSTPUTHEADDELETE
  • PROTOCOL http or https protocol (only available when there is an https proxy in front of Elasticsearch)
  • HOST The hostname of any node in the Elasticsearch cluster, or localhost if it is a local node
  • PORT The port where the Elasticsearch HTTP service is located, the default is 9200
  • PATH API path (eg _count will return the number of documents in the cluster), PATH can contain multiple components such as _cluster/stats or _nodes/stats/jvm
  • QUERY_STRING Some optional query request parameters, such as ?prettyparameters will make the request return more beautiful and readable JSON data
  • BODY A request body in JSON format (if required by the request)

   Example:

   

curl -XPOST 'http://localhost:9200/_count/?pretty' -H 'Content-Type:application/json' -d '{"query":{"match_all":{}}}'

 

 

 

 

 

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326059967&siteId=291194637