以下のコマンドでelasticsearchとkibanaが立ち上がる
docker-compose up -d
立ち上がったら 、、 �
https://dev.classmethod.jp/articles/elasticsearch-getting-started-07/
https://dev.classmethod.jp/articles/elasticsearch-getting-started-08/
リソース作成・変更
curl -XPUT "http://localhost:9200/customer/external/1" \
-H "Content-Type: application/json" \
-d '{
"query": {
"terms": {
"name": "taro", "cook_time_min": [10, 15, 20]
}
}
}'
# リソース作成にあたってURLのID指定がない場合は自動でIDが割り当てられる
curl -XPOST "http://localhost:9200/customer/external" \
-H "Content-Type: application/json" \
-d '{
"query": {
"terms": {
"name": "taro3", "cook_time_min": [10, 15, 20]
}
}
}'
curl -XPOST "http://localhost:9200/test/recipes/2" \
-H "Content-Type: application/json" \
-d @./data/recipes/basil-and-pesto-hummus.json
リソース削除
curl -XDELETE "http://localhost:9200/customer/external/2"
curl -XPOST "http://localhost:9200/customer/external/_bulk" \
-H "Content-Type: application/json" \
-d '
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe2" }
{"index":{"_id":"3"}}
{"name": "Jane Doe3" }
'
curl -XPOST "http://localhost:9200/customer/external/_bulk" \
-H "Content-Type: application/json" \
-d '
{"update":{"_id":"1"}}
{"doc": {"name": "John Doe becomes Jane Doe"}}
{"delete":{"_id":"2"}}
'
データ挿入
curl -XPOST 'localhost:9200/classmethod/employees/_bulk?pretty' \
-H "Content-Type: application/json" \
--data-binary "@./data/employees/employees.jsonl"
curl 'localhost:9200/_cat/indices?v&index=classmethod'
全件
curl 'localhost:9200/classmethod/employees/_search' \
-H "Content-Type: application/json" \
-d '
{
"_source": {
"exclude": ["joined_date", "friends"]
},
"query": {
"match_all": {}
}
}
'
ページング
# size : 件数
# from : (先頭から)スキップする件数
curl 'localhost:9200/classmethod/employees/_search' \
-H "Content-Type: application/json" \
-d '
{
"query": {
"match_all": {}
},
"size": 10,
"from": 0
}
'
フィルタリング
curl 'localhost:9200/classmethod/employees/_search' \
-H "Content-Type: application/json" \
-d '
{
"_source": {
"include": ["employee_id", "firstname"]
},
"query": {
"match" : {
"firstname": "tammy"
}
}
}
'