Elasticsearch 6を利用して検索の検証を何回かで行ってみます。
Elasticsearh はElastic社によりメンテナンスされている構造型、非構造型など様々なデータの検索を行うことができるソフトウェアですが、同様の機能を持つプロダクトのsolrと比べて2014年の前半からGoogleトレンドでも逆転し、現在では4倍近くの差が出ています。
2015年の1月にAWSでAmazon Elasticsearch Serviceが開始されたのも大きでしょう。
https://aws.amazon.com/jp/blogs/aws/new-amazon-elasticsearch-service/
Elasticseach ですが現在ではバージョン6.3が最新のものとなっております。
バージョンの推移は以下となります。
バージョン情報 | GA(一般提供開始日) |
0.4 | 2010/2/8 |
1.0.x | 2014/2/12 |
2.0.x | 2015/10/28 |
2.1.x | 2015/11/24 |
2.2.x | 2016/2/2 |
2.3.x | 2016/3/30 |
2.4.x | 2016/8/28 |
5.0.x | 2016/10/26 |
5.4.x | 2017/5/4 |
5.5.x | 2017/7/6 |
5.6.x | 2017/9/11 |
6.0.x | 2017/11/14 |
6.1.x | 2017/12/12 |
6.2.x | 2018/2/6 |
6.3.x | 2018/6/13 |
2.4系から5.0系に一気に進んだのはKibana、Logsash、Beatsなどの周辺ソフトウェアとのバージョンを合わせるためとなっております。
Elasticsearch のメンテナンスポリシーでは、最新2世代のメジャーバージョンに対してのみメンテナスが行われ、現在では6.3.xと5.6.xにリリースが維持されています。
次の7.0.0がGAになるタイミングで5.6.xのメンテナンスが終了になります。
また、 Elasticsearch のインデックスが利用できるのは一つ先のメジャーリリースのみとなります。
現在の6系では2系のインデックスは動作しません。
2系のインデックスの移行は5系のみで動作します。
もし2系のインデックスを6系で利用する場合は、一旦5系に上げてから6系にアップグレードする必要があります。
また、6系になった際に大きく機能が変更していますので、それまで Elasticsearch を利用していた場合は利用に注意が必要です。
★ Elasticsearch 6 を利用する前に把握しておいた方がよさそうなこと
https://dev.classmethod.jp/server-side/elasticsearch/elasticsearch-6-breaking-changes/
非常にアップデートが早いソフトウェアですので利用に際してはが必要です。
Elasticsearch を Docker で利用してみる
利用としてはローカルの検証環境でのテストが便利です。
Dockerhubの公式サイトではバージョンが5までのものが置いておあります。
https://hub.docker.com/_/elasticsearch/
ただ、最新のものはDockerhubの公式サイトにもありますように、6系以降の最新版は以下の Elastic社から取得できます。
https://www.docker.elastic.co/
それでは、検証するためのDockerfileの設定をしてみます。
1 2 3 4 5 6 |
FROM docker.elastic.co/elasticsearch/elasticsearch:6.3.2 # kuromojiをインストール RUN elasticsearch-plugin install analysis-kuromoji |
今回、検証では日本語の判定を行いたいと思います。
その際に文章の中で適切な語句を取り出す必要があるため形態素解析などの技術を使い単語分別をする必要になります。
日本語を扱うためのプラグインでは「Kuromoji」と「ICU(International Components for Unicode)」が公式ドキュメントにも記載されています。
以下のサイトがこちらについて非常によくまとまっています。
★ Elasticsearch を日本語で使う設定のまとめ
https://qiita.com/shin_hayata/items/41c07923dbf58f13eec4
以下のコマンドで起動を行えます。
1 2 3 4 5 |
$ docker build -f Dockerfile -t elasticsearch:test . $ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:test |
さて、別ターミナルで情報の取得を行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ curl localhost:9200 { "name" : "oWTbrVP", "cluster_name" : "docker-cluster", "cluster_uuid" : "LHU52NoqQXKr_dB38nGv8g", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } |
バージョン情報などが無事確認できました。
念のためkuromojiのプラグインが入っているのも確認してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
$ curl -X GET 'http://localhost:9200/_nodes/plugins?pretty' { "_nodes" : { "total" : 1, "successful" : 1, "failed" : 0 }, "cluster_name" : "docker-cluster", "nodes" : { "5Q3FyrCEQpmw_ggoNvpCCg" : { "name" : "5Q3FyrC", "transport_address" : "172.17.0.2:9300", "host" : "172.17.0.2", "ip" : "172.17.0.2", "version" : "6.3.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "053779d", "roles" : [ "master", "data", "ingest" ], "attributes" : { "ml.machine_memory" : "2096058368", "xpack.installed" : "true", "ml.max_open_jobs" : "20", "ml.enabled" : "true" }, "plugins" : [ { "name" : "analysis-kuromoji", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "The Japanese (kuromoji) Analysis plugin integrates Lucene kuromoji analysis module into elasticsearch.", "classname" : "org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "ingest-geoip", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Ingest processor that uses looksup geo data based on ip adresses using the Maxmind geo database", "classname" : "org.elasticsearch.ingest.geoip.IngestGeoIpPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "ingest-user-agent", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Ingest processor that extracts information from a user agent", "classname" : "org.elasticsearch.ingest.useragent.IngestUserAgentPlugin", "extended_plugins" : [ ], "has_native_controller" : false } ], "modules" : [ { "name" : "aggs-matrix-stats", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Adds aggregations whose input are a list of numeric fields and output includes a matrix.", "classname" : "org.elasticsearch.search.aggregations.matrix.MatrixAggregationPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "analysis-common", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Adds \"built in\" analyzers to Elasticsearch.", "classname" : "org.elasticsearch.analysis.common.CommonAnalysisPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "ingest-common", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Module for ingest processors that do not require additional security permissions or have large dependencies and resources", "classname" : "org.elasticsearch.ingest.common.IngestCommonPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "lang-expression", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Lucene expressions integration for Elasticsearch", "classname" : "org.elasticsearch.script.expression.ExpressionPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "lang-mustache", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Mustache scripting integration for Elasticsearch", "classname" : "org.elasticsearch.script.mustache.MustachePlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "lang-painless", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "An easy, safe and fast scripting language for Elasticsearch", "classname" : "org.elasticsearch.painless.PainlessPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "mapper-extras", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Adds advanced field mappers", "classname" : "org.elasticsearch.index.mapper.MapperExtrasPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "parent-join", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "This module adds the support parent-child queries and aggregations", "classname" : "org.elasticsearch.join.ParentJoinPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "percolator", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Percolator module adds capability to index queries and query these queries by specifying documents", "classname" : "org.elasticsearch.percolator.PercolatorPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "rank-eval", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "The Rank Eval module adds APIs to evaluate ranking quality.", "classname" : "org.elasticsearch.index.rankeval.RankEvalPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "reindex", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "The Reindex module adds APIs to reindex from one index to another or update documents in place.", "classname" : "org.elasticsearch.index.reindex.ReindexPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "repository-url", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Module for URL repository", "classname" : "org.elasticsearch.plugin.repository.url.URLRepositoryPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "transport-netty4", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Netty 4 based transport implementation", "classname" : "org.elasticsearch.transport.Netty4Plugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "tribe", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Tribe module", "classname" : "org.elasticsearch.tribe.TribePlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "x-pack-core", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Core", "classname" : "org.elasticsearch.xpack.core.XPackPlugin", "extended_plugins" : [ ], "has_native_controller" : false }, { "name" : "x-pack-deprecation", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Deprecation", "classname" : "org.elasticsearch.xpack.deprecation.Deprecation", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-graph", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Graph", "classname" : "org.elasticsearch.xpack.graph.Graph", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-logstash", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Logstash", "classname" : "org.elasticsearch.xpack.logstash.Logstash", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-ml", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Machine Learning", "classname" : "org.elasticsearch.xpack.ml.MachineLearning", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : true }, { "name" : "x-pack-monitoring", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Monitoring", "classname" : "org.elasticsearch.xpack.monitoring.Monitoring", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-rollup", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Rollup", "classname" : "org.elasticsearch.xpack.rollup.Rollup", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-security", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Security", "classname" : "org.elasticsearch.xpack.security.Security", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-sql", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "The Elasticsearch plugin that powers SQL for Elasticsearch", "classname" : "org.elasticsearch.xpack.sql.plugin.SqlPlugin", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-upgrade", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Upgrade", "classname" : "org.elasticsearch.xpack.upgrade.Upgrade", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false }, { "name" : "x-pack-watcher", "version" : "6.3.2", "elasticsearch_version" : "6.3.2", "java_version" : "1.8", "description" : "Elasticsearch Expanded Pack Plugin - Watcher", "classname" : "org.elasticsearch.xpack.watcher.Watcher", "extended_plugins" : [ "x-pack-core" ], "has_native_controller" : false } ] } } } |
次回以降に動作の確認などを行っていきます。
★関連記事
Elasticsearch 6 を使ったデータ検証 その2(マッピングの登録をしてみる)
Elasticsearch 6 を使ったデータ検証 その3(bulkでデータを投入してみる)
Elasticsearch 6 を使ったデータ検証 その4(チュートリアル記事とデータの検索での比較)
Elasticsearch 6 を使ったデータ検証 その5(クエリでの検索)
Elasticsearch 6 を使ったデータ検証 その6(Aggregationを使った分類・集計)
Elasticsearch 6 を使ったデータ検証 その7(Analyzerについて)
このブログは株式会社CoLabMixによる技術ブログです。
GCP、AWSなどでのインフラ構築・運用や、クローリング・分析・検索などを主体とした開発を行なっています。
Ruby on RailsやDjango、Pythonなどの開発依頼などお気軽にお声がけください。
開発パートナーを増やしたいという企業と積極的に繋がっていきたいです。
お問い合わせやご依頼・ご相談など