全文検索エンジンにElasticSearchを使ってみます
今まで全文検索エンジンはSolr派だったのですが、トレンドでいうとElasticSearchのほうが世界的には人気のようで・・・ ということで勉強も兼ねて、今回は全文検索エンジンにElasticSearchを使ってみようと思います。

ElasticSearchにIndexを作成する
Solrの場合、コマンドを実行することでコア(index)を作成しますが、ElasticSearcの場合、HTTP-APIにリクエストを投げて作るようなので、公式ページにある以下のコマンドを実行
% docker-compose up -d elasticsearch
上記のコマンドでElasticSearchを起動して
curl -X PUT "http://localhost:9200/d_anime"
上記のコマンドでコアを作成できます
とりあえず動作確認
http://localhost:9200/d_anime/
結果
{
"d_anime": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1631425258572",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "7jtaoMllRkGOpTKATtC2UA",
"version": {
"created": "7090199"
},
"provided_name": "d_anime"
}
}
}
}
ひとまずインデックスは作成されました。
次は検索結果
http://localhost:9200/d_anime/_search
結果
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
まだ中身が空っぽなのでデータの返却はないですが、人まずは検索が動いているようです。
とりあえず以上です
ひとまずElasticSearchが動いたところまで確認できました。本当はlogstashを利用したデータ取り込みまでやってみたかったのですが、理解が追いつかず、次回に持ち越しです・・・