1
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?

OpenSearchコマンド

ElasticSearchと微妙に差異があるので備忘録に
自分でよく使うもののみ

起動確認

curl -XGET 'localhost:9200/'

インデックス

一覧

curl -XGET 'localhost:9200/_cat/indices?v'

設定確認

curl -XGET 'localhost:9200/{indexName}/_settings?pretty'

マッピング確認

curl -XGET 'localhost:9200/{indexName}/_mapping?pretty'

インデックス削除

curl -XDELETE 'localhost:9200/{indexName}?pretty'

エイリアス

エイリアス追加

curl -H Content-Type:application/json -XPOST 'localhost:9200/_aliases' -d 
'{"actions": [{"add": {"index": "{indexName}", "alias": "{aliasName}"}}]}'

エイリアス確認

curl -XGET 'localhost:9200/_aliases?pretty'

ドキュメント

件数確認

curl -XGET 'localhost:9200/{indexName}/_count?pretty'

フィールド定義追加

curl -H Content-Type:application/json -XPOST 'localhost:9200/{indexName}/_mappings/?pretty' -d '
{
  "properties" : {
    "field1" : {
      "type" : "text"
    },
    "field2" : {
      "type" : "keyword"
    }
  }
}'

ドキュメント追加

curl -H Content-Type:application/json -XPOST 'localhost:9200/{indexName}/_update/{_id}' --d '
{
  "doc": { "name": "Jhon Doe", "age": 20 }
}'

ドキュメント更新

curl -H Content-Type:application/json -XPOST 'localhost:9200/{indexName}/_update/{_id}' --d '
{
  "doc": { "name": "Jhone Doe", "age": 21 }
}'

ドキュメント取得

curl -XGET 'localhost:9200/{indexName}/_doc/{_id}?pretty'

ドキュメント検索(条件無)

curl -XGET 'localhost:9200/{indexName}/_search?pretty'

ドキュメント検索(条件有)

curl -H Content-Type:application/json -XGET 'localhost:9200/{indexName}/_search?pretty' -d '
{
  "query": {
    "match": {
      "name": "Jhon"
    }
  }
}
'

リインデックス

curl -H Content-Type:application/json -XPOST 'localhost:9200/_reindex?pretty' -d '
{
  "source": {
    "index": "fromIndex"
  },
  "dest": {
    "index": "toIndex"
  }
}'

その他

ユーザー名

きめ細かなアクセスコントロールの機能を使っていてユーザー名を指定する必要がある時は以下のようにユーザー名とパスワードを指定する

curl -u {USERNAME}:{PASSWORD} -XGET 'localhost:9200/_cat/indices?v'

書き出したjsonファイルを使う

xxx.json
{
    "name": "Jhon Doe", 
    "age": 20
}
curl -H Content-Type: application/json -XPOST 'localhost:9200/{indexName}/_doc/' -d @xxx.json

参考にした記事

1
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
1
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?