Apache Solrを動かしてみる

とりあえず動くようにする

# wget
wget http://ftp.jaist.ac.jp/pub/apache/lucene/solr/6.0.1/solr-7.4.0.tgz
sudo tar -zvxf solr-7.4.0.tgz

# Homebrew
brew install solr

# solr start に -e techproducts オプションをつけるとサンプルデータが登録される
solr start -e techproducts
solr stop

./bin/solr start
# solr startしてからコアの作成を行う
 create -c sample_core
# jsonをポストする
post -c sample_core hoge.json

solr 6系以降はデフォルトでスキーマレスモードになっているらしく、これだけでも最低限は動くようになります。

schema.xmlで管理するようにする

Solrはデフォルトでスキーマレスモードになっているので、solrconfig.xmlに以下の設定を追加する

<luceneMatchVersion>7.4.0</luceneMatchVersion>
+<schemaFactory class="ClassicIndexSchemaFactory"/>

json形式のドキュメントを一括削除

curl -H 'Content-Type: application/json' 'http://localhost:8983/solr/[コア名]/update?commit=true' -d '{ delete: { query: "*:*" }}'

コアをリロードする

curl 'http://localhost:8983/solr/admin/cores?wt=json&action=RELOAD&core=[コア名]'