Elasticsearchとは
分散型全文検索システム
データ構造
文字列処理(analyzer)
インストール
※indexが壊れる可能性があるため、java7u25未満またはjava7u55以上を利用する
root@hostname:/home/shimizu# aptitude install elasticsearch 以下の新規パッケージがインストールされます: ant{a} ant-optional{a} ca-certificates-java{a} dbus{a} dbus-x11{a} default-jre{a} default-jre-headless{a} elasticsearch file{a} fontconfig{a} fonts-dejavu-extra{a} gconf-service{a} gconf2{a} gconf2-common{a} gnome-mime-data{a} hicolor-icon-theme{a} java-common{a} libasound2{a} libasound2-data{a} libasyncns0{a} libatk-wrapper-java{a} libatk-wrapper-java-jni{a} libatk1.0-0{a} libatk1.0-data{a} libavahi-client3{a} libavahi-common-data{a} libavahi-common3{a} libavahi-glib1{a} libbonobo2-0{a} libbonobo2-common{a} libcairo2{a} libcanberra0{a} libcap-ng0{a} libcups2{a} libdatrie1{a} libdbus-1-3{a} libdbus-glib-1-2{a} libdom4j-java{a} libdrm-intel1{a} libdrm-nouveau2{a} libdrm-radeon1{a} libdrm2{a} libelf1{a} libflac8{a} libgconf-2-4{a} libgconf2-4 libgdk-pixbuf2.0-0{a} libgdk-pixbuf2.0-common{a} libgif4{a} libgl1-mesa-dri{a} libgl1-mesa-glx{a} libglapi-mesa{a} libglib2.0-0{a} libglib2.0-data{a} libgnome-2-0 libgnome2-0 libgnome2-bin libgnome2-common libgnomevfs2-0 libgnomevfs2-common libgnomevfs2-extra libgraphite2-3{a} libgtk2.0-0{a} libgtk2.0-bin{a} libgtk2.0-common{a} libharfbuzz0b{a} libhyperic-sigar-java{a} libice6{a} libisorelax-java{a} libjasper1{a} libjaxen-java{a} libjbig0{a} libjdom1-java{a} libjna-java{a} libjna-jni{a} libjpeg62-turbo{a} libjts-java{a} liblcms2-2{a} libllvm3.5{a} liblog4j1.2-java{a} libltdl7{a} liblucene4-java{a} libmagic1{a} libmsv-java{a} libnspr4{a} libnss3{a} libogg0{a} liborbit-2-0{a} libpango-1.0-0{a} libpangocairo-1.0-0{a} libpangoft2-1.0-0{a} libpciaccess0{a} libpcsclite1{a} libpixman-1-0{a} libpulse0{a} libpython-stdlib{a} libpython2.7-minimal{a} libpython2.7-stdlib{a} librelaxng-datatype-java{a} libsm6{a} libsndfile1{a} libspatial4j-java{a} libtdb1{a} libthai-data{a} libthai0{a} libtiff5{a} libtxc-dxtn-s2tc0{a} libvorbis0a{a} libvorbisenc2{a} libvorbisfile3{a} libx11-xcb1{a} libxcb-dri2-0{a} libxcb-dri3-0{a} libxcb-glx0{a} libxcb-present0{a} libxcb-render0{a} libxcb-shm0{a} libxcb-sync1{a} libxcomposite1{a} libxcursor1{a} libxdamage1{a} libxerces2-java{a} libxfixes3{a} libxi6{a} libxinerama1{a} libxml-commons-external-java{a} libxml-commons-resolver1.1-java{a} libxom-java{a} libxpp2-java{a} libxpp3-java{a} libxrandr2{a} libxrender1{a} libxshmfence1{a} libxtst6{a} libxxf86vm1{a} mime-support{a} openjdk-7-jre{a} openjdk-7-jre-headless{a} psmisc{a} python{a} python-minimal{a} python2.7{a} python2.7-minimal{a} shared-mime-info{a} tzdata-java{a} xdg-user-dirs{a} 更新: 0 個、新規インストール: 146 個、削除: 0 個、保留: 0 個。 126 M バイトのアーカイブを取得する必要があります。展開後に 285 M バイトのディスク領域が新たに消費されます。 先に進みますか? [Y/n/?] y ... root@hostname:/home/shimizu# vi /etc/default/elasticsearch ===以下をコメントアウト START_DAEMON=true ES_USER=elasticsearch ES_GROUP=elasticsearch LOG_DIR=/var/log/elasticsearch DATA_DIR=/var/lib/elasticsearch ===追加設定 ES_HEAP_SIZE=128m # 潤沢に割り当てるべし === root@hostname:/home/shimizu# /etc/init.d/elasticsearch start [ ok ] Starting elasticsearch (via systemctl): elasticsearch.service. ### nameはノード名 ### root@hostname:/home/shimizu# curl -X GET http://localhost:9200/ { "status" : 200, "name" : "Anti-Cap", "version" : { "number" : "1.0.3", "build_hash" : "NA", "build_timestamp" : "NA", "build_snapshot" : false, "lucene_version" : "4.6" }, "tagline" : "You Know, for Search" } ### クラスタのヘルスチェックAPI ### ### クラスタ名がデフォルトで"elasticsearch"なので変更するべし(他のノードが追加された時に意図せずクラスタの一部として認識されてしまう) ### root@hostname:/home/shimizu# curl -X GET http://localhost:9200/_cluster/health {"cluster_name":"elasticsearch","status":"green","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0} ### ノード情報取得API ### root@hostname:/home/shimizu# curl -X GET http://localhost:9200/_cluster/nodes No handler found for uri [/_cluster/nodes] and method [GET]
基本操作
### indexの登録 ### root@hostname:/home/shimizu# curl -XPUT http://localhost:9200/prefecture {"acknowledged":true} ### typeの登録 ### root@hostname:/home/shimizu# curl -XPUT http://localhost:9200/prefecture/central/_mapping -d '{ > "central": { > "properties": { > "name": { "type": "string" }, > "central": { "type": "string" }, > "date": { "type":"date", "format":"yyyy/MM/dd"} > } > } > }' {"acknowledged":true} ### document登録 ### root@hostname:/home/shimizu# curl -XPUT http://localhost:9200/prefecture/central/1 -d ' > { > "name": "北海道", > "central": "札幌", > "date": "'`/bin/date +%Y/%m/%d`'" > }' {"_index":"prefecture","_type":"central","_id":"1","_version":1,"created":true} root@hostname:/home/shimizu# curl -XPUT http://localhost:9200/prefecture/central/2 -d ' > { > "name": "青森", > "central": "青森", > "date": "'`/bin/date +%Y/%m/%d`'" > }' {"_index":"prefecture","_type":"central","_id":"2","_version":1,"created":true} ### documentの取得 ### root@hostname:/home/shimizu# curl -XGET http://localhost:9200/prefecture/central/1 {"_index":"prefecture","_type":"central","_id":"1","_version":1,"found":true, "_source" : { "name": "北海道", "central": "札幌", "date": "2015/06/19" }} root@hostname:/home/shimizu# curl -XGET http://localhost:9200/prefecture/central/1?fields=name {"_index":"prefecture","_type":"central","_id":"1","_version":1,"found":true,"fields":{"name":["北海道"]}}
Elastic HQ
データのブラウズやインデックス管理が可能
root@hostname:/home/shimizu# cd /usr/share/elasticsearch/bin/ root@hostname:/usr/share/elasticsearch/bin# ./plugin -install royrusso/elasticsearch-HQ -> Installing royrusso/elasticsearch-HQ... Trying https://github.com/royrusso/elasticsearch-HQ/archive/master.zip... Downloading ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE Installed royrusso/elasticsearch-HQ into /usr/share/elasticsearch/plugins/HQ Identified as a _site plugin, moving to _site structure ...
プラグインインストールにあたりElasticsearchの再起動は不要
bigdesk
JXM的な負荷確認やクラスター管理可能
root@hostname:/usr/share/elasticsearch/bin# ./plugin -install lukas-vlcek/bigdesk -> Installing lukas-vlcek/bigdesk... Trying https://github.com/lukas-vlcek/bigdesk/archive/master.zip... Downloading .......................................................................................................................................................................................................................DONE Installed lukas-vlcek/bigdesk into /usr/share/elasticsearch/plugins/bigdesk Identified as a _site plugin, moving to _site structure ...
プラグインインストールにあたりElasticsearchの再起動は不要
head
root@hostname:/usr/share/elasticsearch/bin# ./plugin -install mobz/elasticsearch-head -> Installing mobz/elasticsearch-head... Trying https://github.com/mobz/elasticsearch-head/archive/master.zip... Downloading ..........................................................................................................................................................................................................................................................................................DONE Installed mobz/elasticsearch-head into /usr/share/elasticsearch/plugins/head Identified as a _site plugin, moving to _site structure ...
プラグインインストールにあたりElasticsearchの再起動は不要
参考
Elasticsearchチュートリアル
http://code46.hatenablog.com/entry/2014/01/21/115620
Elastic HQ を使ってみた(1)
http://inokara.hateblo.jp/entry/2013/12/19/072015
elasticsearch version0.20.6の設定
http://tree-tips.appspot.com/elasticsearch/config/elasticsearch_yml/
ElasticSearchの運用とか (2)
http://t-cyrill.hatenablog.jp/entry/2014/04/19/161422