Solr 4.0 の _version_ フィールド

Solr 4.0 で 3.x のときのままの schema.xml 流用すると、 4.0 のサンプルに含まれる solrconfig.xml などと組み合わせたときに管理画面やログに下のようなエラーが吐かれることがある。

org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Unable to use updateLog: _version_field must exist in schema, using indexed="true" stored="true" and multiValued="false" (_version_ does not exist)

3.x のときには聞いたことなかった _version_ フィールドとは何者なのかと調べてみると、下記ドキュメントにも書いてあるとおり Solr 4.0 から追加された Realtime Get など、 update log を使ういくつかの機能に必要なフィールドとのこと。

ということで対応策。

  • Solr 4.0 以降では _version_ は recommended field ということなので、下記のような感じでおとなしく schema.xml にフィールドを追加する。
<field name="_version_" type="long" indexed="true" stored="true"/>
  • solrconfig.xml で update log 等の _version_ フィールドに依存する機能を無効可する。
    • サンプルの solrconfig.xml だと下記2箇所かな。
      • updateHandler セクションの <updateLog> のあたり
      • <requestHandler name="/get" class="solr.RealTimeGetHandler"> のあたり
    • Realtime Get 関連の設定項目についてはこちらも参照

これでエラー出さずに起動するようになる。