Docker 入門
Elasticsearch で全文検索を実行する(Windows PowerShell 7 版)
各種設定の確認
前のページまでの作業で様々なコマンドを利用してきました.ここで代表的なコマンドをまとめておきます.
まず,シェル変数に API キーが読み込まれていることを確認します.
PS C:\...\elastic202511> Write-Output "${Env:ES_LOCAL_API_KEY}" ⏎
NlZGY3pwb0IyT1FPR1RNREtrRlc6WG1VUmZnVnYxSmYyMlpFMDQwTHJ6UQ==
PS C:\...\elastic202511>
まだ読み込まれていなければ前のページで作成したスクリプトを実行してファイル .env からシェル変数に読み込みます.
PS C:\...\elastic202511> .\load-env.ps1 ⏎
PS C:\...\elastic202511>
クラスタの健全性
次のコマンドはクラスタ全体の健全性を確認するコマンドです.なお,クラスタに関する説明はここ参照してください.
curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/_cat/indices?v"
実際にコマンドを実行した結果を示します.
PS C:\...\elastic202511> curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/_cat/indices?v" ⏎
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size dataset.size
green open hyaku_index QZiYybW6TtCvDuGAlIs6Ig 1 0 0 0 249b 249b 249b
PS C:\...\elastic202511>
インデックスの健全性
次はインデックスの健全性を確認するためのコマンドです.
curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/_cat/indices?v"
実際に実行した結果は次のようになりました.
PS C:\...\elastic202511> curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/_cat/indices?v" ⏎ health status index uuid pri rep docs.count docs.deleted store.size pri.store.size dataset.size green open hyaku_index QZiYybW6TtCvDuGAlIs6Ig 1 0 0 0 249b 249b 249b PS C:\...\elastic202511>
インデックス設定
インデックスの設定を確認するためのコマンドは次のとおりです.
curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_settings?pretty"
実際に実行した結果は次のようになりました.
PS C:\...\elastic202511> curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_settings?pretty" ⏎
{
"hyaku_index" : {
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "hyaku_index",
"creation_date" : "1764397369669",
"analysis" : {
"normalizer" : {
"lowercase_normalizer" : {
"filter" : [
"lowercase"
],
"type" : "custom"
}
},
"analyzer" : {
"hyaku_kuromoji_analyzer" : {
"filter" : [
"kuromoji_baseform",
"kuromoji_part_of_speech",
"ja_stop",
"lowercase"
],
"type" : "custom",
"tokenizer" : "kuromoji_tokenizer"
},
"kana_reading" : {
"filter" : [
"kuromoji_readingform",
"lowercase"
],
"type" : "custom",
"tokenizer" : "kuromoji_tokenizer"
}
}
},
"number_of_replicas" : "0",
"uuid" : "QZiYybW6TtCvDuGAlIs6Ig",
"version" : {
"created" : "9039001"
}
}
}
}
}
PS C:\...\elastic202511>
マッピング
マッピングの定義を確認するためのコマンドです.
curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_mapping?pretty"
PS C:\...\elastic202511> curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_mapping?pretty" ⏎
{
"hyaku_index" : {
"mappings" : {
"properties" : {
"id" : {
"type" : "long"
},
"kajin" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 128,
"normalizer" : "lowercase_normalizer"
}
},
"analyzer" : "hyaku_kuromoji_analyzer"
},
"kana" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 512
}
},
"analyzer" : "hyaku_kuromoji_analyzer"
},
"uta" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 512
}
},
"analyzer" : "hyaku_kuromoji_analyzer"
}
}
}
}
}
PS C:\...\elastic202511>
ドキュメントの件数
まだ利用していませんでしたが,登録済みドキュメントの件数を確認するためのコマンドです.
curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_count?pretty"
実際にコマンドを実行すると次のような結果が得られました.まだドキュメントを登録していないので結果は 0 件です.
PS C:\...\elastic202511> curl -H "Authorization: ApiKey ${Env:ES_LOCAL_API_KEY}" "http://localhost:9200/hyaku_index/_count?pretty" ⏎ { "count" : 0, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 } } PS C:\...\elastic202511>