0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Elastic Cloud に API でデータを投入する

Last updated at Posted at 2022-04-01

blog-apr0102 というエンジンを作成します。
cloud_apr0100.png

Credentials で private-key を調べます。
cloud_apr0101.png

curl_insert.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-***********"
NAME_ENGINE="blog-apr0102"
#
echo ${PRIVATE-KEY}
#
curl -X POST ${HOST}'/api/as/v1/engines/'${NAME_ENGINE}'/documents' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer '${PRIVATE_KEY} \
  -d@all_data.json
all_data.json
[
{
	"id": "t001",
	"name": "山本太郎",
	"title": "My Name Is Yamato",
	"content": "I love dog",
	"tags": ["red", "green", "blue"]
},
{
	"id": "t002",
	"name": "田中康夫",
	"title": "My Name Is Tanaka",
	"content": "I love cat",
	"tags": ["Earth", "Moon", "Mars"]
},
{
	"id": "t003",
	"name": "渡辺五郎",
	"title": "My Name Is Watanabe",
	"content": "I love fish",
	"tags": ["apple", "orange", "banana"]
}
]

実行結果
cloud_apr0102.png

データの読み込み

Httpie

http_read.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-******"
NAME_ENGINE="blog-apr0102"
#
http GET ${HOST}'/api/as/v1/engines/'$NAME_ENGINE'/documents/list' \
	'Authorization: Bearer '${PRIVATE_KEY} < query00.json
query00.json
{
  "page": {
    "size": 5
}
}

Curl

curl_read.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-******"
NAME_ENGINE="blog-apr0102"
#
#
curl -X GET ${HOST}'/api/as/v1/engines/'$NAME_ENGINE'/documents/list' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer '${PRIVATE_KEY} \
-d '{
  "page": {
    "size": 5
  }
}'

参考

Engines を API で取り扱う方法
参考ページ
Engines API

Create

create_engine.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-********"
#
curl -X POST $HOST'/api/as/v1/engines' \
	-H 'Authorization: Bearer '$PRIVATE_KEY \
	-d '{"name": "blog-apr0102"}'

List

list_engines.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-*******"
#
http $HOST'/api/as/v1/engines' \
	'Authorization: Bearer '$PRIVATE_KEY

Delete

delete_engine.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
PRIVATE_KEY="private-******"
NAME_ENGINE="blog-apr0102"
#
curl -XDELETE $HOST'/api/as/v1/engines/'$NAME_ENGINE \
	-H 'Authorization: Bearer '$PRIVATE_KEY

参考

Python3 の例はこちら
Python3: Elastic Cloud に API でデータを投入する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?