连接集群
通过连接信息页,获取您的ES集群网关地址、用户名和密码。
您可以通过多种方式连接到集群:
cURL
在终端执行以下代码写入测试数据,注意替换成您的用户名及密码。
curl -XPOST 'https://router.nasuyun.com:9200/logs/_doc' -H 'Content-Type: application/json' \
-u your_username:your_password \
-d '
{
"timestamp": "2018-01-24 12:34:56",
"message": "User logged in",
"user_id": 4,
"admin": false
}'
如返回如下结果 表明数据写入成功
{
"_index": "logs",
"_type": "_doc",
"_id": "euuBFIIBcnPik3fA8c8y",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
测试API搜索文档
curl -XPOST 'https://router.nasuyun.com:9200/logs/_search?pretty' -u your_username:your_password
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "euuBFIIBcnPik3fA8c8y",
"_score" : 1.0,
"_source" : {
"timestamp" : "2018-01-24 12:34:56",
"message" : "User logged in",
"user_id" : 4,
"admin" : false
}
}
]
}
}
客户端连接
所有语言都可以使用RESTful API 通过端口9200和Elasticsearch 进行通信,你可以用你最喜爱的 web 客户端访问Elasticsearch
帮助
平台内部已为你准备大量主流编程语言连接代码,可直接复制粘贴到本地环境运行。