Elasticsearchのコマンドをまとめていく
-
インデックス削除
curl -XDELETE "http://localhost:9200/{index}" -
マッピングの作成
curl -XPUT "http://localhost:9200/blog" --data-binary @blog.json
blog.jsonの中身
{
"mappings": {
"blogpost": {
"properties": {
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
}
- データ登録
curl -XPUT "http://localhost:9200/blog/blogpost/1" --data-binary @data.json
data.jsonの中身
{
"title": "Nest eggs",
"body": "Making your money work...",
"comments": [
{
"name": "John Smith",
"comment": "Great article",
"age": 28,
"stars": 4,
"date": "2014-09-01"
},
{
"name": "Alice White",
"comment": "More like this please",
"age": 31,
"stars": 5,
"date": "2014-10-22"
}
]
}
-
インデックスの検索
curl -XGET "http://localhost:9200/{index}/_search" -
インデックスの検索(条件付き)
curl -XPOST "http://localhost:9200/blog/_search" @search.json
search.jsonの中身
{
"query": {
"nested": {
"path": "comments",
"filter": {
"range": {
"comments.date": {
"gte": "2014-10-01",
"lt": "2014-11-01"
}
}
}
}
},
"sort": {
"comments.stars": {
"order": "asc",
"mode": "min",
"nested_filter": {
"range": {
"comments.date": {
"gte": "2014-10-01",
"lt": "2014-11-01"
}
}
}
}
}
}
-
バージョン確認
http://localhost:9200/ -
インデックスをCloseする
curl -XPOST "http://localhost:9200/{index}/_close" -
インデックスをOpenする
curl -XPOST "http://localhost:9200/{index}/_open" -
状態を確認
curl -XGET "http://localhost:9200/_cat/indices"