Baidu AI Cloud
中国站

百度智能云

Elasticsearch

Access the Elasticsearch Service

After building the Elasticsearch cluster, connect the cluster through any HTTP client to import or query data. Note that the Elasticsearch is within the user-defined vpc during cluster creation, and only the bccs in the same vpc can access ES services. By default, there's only one superuser, and its password is the administrator's password specified when the user creates the cluster. By taking the curl command under Linux as an example, introduce how to access ES services.

For example, access the cluster by Http Basic authentication:

By parameter authentication:

Create an index

Create an index through the index API (with user name and password) created through Elasticsearch:

curl -u username:password -XPUT host:port/index_name

Import data

Real-time import:

curl -u username:password -XPOST 'host:port/index_name/type/id' -d '
{

    "field": "value"
}

The id is the unique id of the data. If you do not specify an id, the system generates one randomly.

Batch import:

curl -u username:password -XPOST 'host:port/index_name/type/_bulk?pretty' -d '
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'

Every two rows form one data and must get separated by a newline character. Import the file using the following command:

curl -u username:password -XPOST 'host:port/index_name/type/_bulk' --data-binary @import.json

Import.json is the file name, and a single file cannot exceed 100M. A large file can be divided into small files and import in parallel.

Query

List all indexes in the cluster:

curl -u username:password -XGET 'host:port/_cat/indices?v'

Query data in the index:

curl -u username:password -XGET 'host:port/testindex/_search?pretty' -d '
{

    "query": { "match_all": {} }
}'

For other detailed API introduction of the Elasticsearch, see the official documentations of the Elasticsearch:

https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

Delete a cluster

If you do not want to use the cluster after a simple test, you need to delete it. For this purpose, click the "Delete" button at the upper right corner on the "Cluster Information" page, and then click "Confirm":

image.png

After deleting the cluster, all the data get cleared and cannot be recovered. Meanwhile, you do not need to pay for it any longer.

Previous
Create a Cluster
Next
User Manual