Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save satom9to5/9945657 to your computer and use it in GitHub Desktop.
Save satom9to5/9945657 to your computer and use it in GitHub Desktop.

pluginコマンドのパス

/usr/share/elasticsearch/bin/以下(※Ver1.3.2で確認)

Elasticsearch-river-plugin

HP

https://github.com/elasticsearch/elasticsearch-river-wikipedia

※ElasticSearchのバージョンによってインストールするバージョンが異なるため注意

インストール

bin/plugin -install elasticsearch/elasticsearch-river-wikipedia/2.0.0

Kuromoji

HP

https://github.com/elasticsearch/elasticsearch-analysis-kuromoji

インストール

bin/plugin -install elasticsearch/elasticsearch-analysis-kuromoji/2.0.0

ElasticSearch設定変更

ヒープサイズ変更

# vi /etc/sysconfig/elasticsearch
ES_HEAP_SIZE=2g

インポート

インデックス作成

$ curl -XPUT 'http://localhost:9200/ja-wikipedia-kuromoji/' -d'
{
    "index":{
        "analysis":{
            "tokenizer" : {
                "kuromoji_user_dict" : {
                   "type" : "kuromoji_tokenizer",
                   "mode" : "extended",
                   "discard_punctuation" : "false"
                }
            },
            "analyzer" : {
                "my_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "kuromoji_user_dict"
                }
            }

        }
    }
}
'

注意点

  • サンプルには「user_dictionary」が存在したが、特に必要ないため除外した
  • JSONの最後の要素はカンマを外すこと!

インポート

$ curl -XPUT 'http://localhost:9200/_river/ja-wikipedia-kuromoji/_meta' -d '
{
    "type" : "wikipedia",
    "wikipedia" : {
        "url" : "file:/wikipedia/jawiki-latest-pages-articles.xml"
    },
    "index" : {
        "bulk_size" : 10000
    }
}'

※すぐ結果が返ってくるが、インポート処理はバックグラウンドで行われている 現在の状態は/var/log/elasticsearch/elasticsearch.logでも確認できるが、/var/lib/elasticsearch/elasticsearch/nodes/以下のインデックスディレクトリの容量変化を見て確認した方がいいかも。

状態確認

$ curl -XGET 'localhost:9200/_river/ja-wikipedia-kuromoji/_search?pretty'
{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "_river",
      "_type" : "ja-wikipedia-kuromoji",
      "_id" : "_meta",
      "_score" : 1.0, "_source" :
{
    "type" : "wikipedia",
    "wikipedia" : {
        "url" : "file:/vagrant/wikipedia/jawiki-latest-pages-articles.xml"
    },
    "index" : {
        "bulk_size" : 10000
    }
}
    }, {
      "_index" : "_river",
      "_type" : "ja-wikipedia-kuromoji",
      "_id" : "_status",
      "_score" : 1.0, "_source" : {"node":{"id":"GsmCL7nnSKaSsJ1Nhhuaxg","name":"Honey Lemon","transport_address":"inet[/10.0.2.15:9300]"}}
    } ]
  }
}

river停止

$ curl -XDELETE 'localhost:9200/_river/ja-wikipedia-kuromoji/'

ログに以下のような内容が吐き出されて停止される

[2014-04-10 08:36:19,727][INFO ][cluster.metadata         ] [Honey Lemon] [[_river]] remove_mapping [[ja-wikipedia-kuromoji]]
[2014-04-10 08:36:19,742][INFO ][river.wikipedia          ] [Honey Lemon] [wikipedia][ja-wikipedia-kuromoji] closing wikipedia river

削除

$ curl -XDELETE 'localhost:9200/ja-wikipedia-kuromoji/'

検索

query以下に、クエリの種類(以下例では「query_string」)を指定し、 その後に検索条件を記載するっぽい

例:

curl -XGET 'localhost:9200/ja-wikipedia-kuromoji/_search?pretty' -d '
{
  "query":{
    "query_string":{
      "default_field":"page.title",
      "query":"ラーメン"
    }
  }
}'

river用各種URL

  • _search
  • _meta
  • _status
  • _mapping

参考URL

http://blog.johtani.info/blog/2013/09/03/ja-wikipedia-with-kuromoji/
http://lab.synergy-marketing.co.jp/blog/other/solr-vs-elasticsearch-japanese-analysis-settings http://easyramble.com/elasticsearch-queries-and-filters.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment