Config API

Config APIを使用すると、RESTライクなAPI呼び出しを使用してsolrconfig.xmlのさまざまな側面を操作できます。

この機能はデフォルトで有効になっており、SolrCloud、ユーザー管理クラスタ、およびシングルノードインストールの両方で同様に機能します。キャッシュサイズやコミット設定など、一般的に編集されるプロパティやリクエストハンドラー定義の多くは、このAPIで変更できます。

このAPIを使用する場合、solrconfig.xmlは変更されません。代わりに、編集されたすべての構成はconfigoverlay.jsonというファイルに保存されます。configoverlay.jsonの値は、solrconfig.xmlの値よりも優先されます。

Config APIエンドポイント

すべてのConfig APIエンドポイントはコレクション固有です。つまり、このAPIは一度に1つのコレクションの構成を検査または変更できます。

  • collection/config:有効なフル構成を取得するか、構成を変更します。取得にはGETを使用し、コマンド実行にはPOSTを使用します。

  • collection/config/overlayconfigoverlay.jsonの詳細のみを取得し、solrconfig.xmlで直接またはデフォルトで暗黙的に定義されたオプションを削除します。

  • collection/config/paramssolrconfig.xmlで定義されたパラメータをオーバーライドまたは置き換えることができるパラメータセットを作成します。このエンドポイントの詳細については、リクエストパラメータAPIを参照してください。

構成の取得

すべての構成項目は、/configエンドポイントにGETリクエストを送信することで取得できます。

V1 API

https://127.0.0.1:8983/solr/techproducts/config

V2 API

https://127.0.0.1:8983/api/collections/techproducts/config

レスポンスは、configoverlay.jsonの設定とsolrconfig.xmlの設定をマージした結果のSolr構成になります。

返される構成を、queryrequestHandlerupdateHandlerなどのトップレベルのセクションに制限できます。これを行うには、セクションの名前をconfigエンドポイントに追加します。たとえば、すべてのリクエストハンドラーの構成を取得するには、次のようにします。

V1 API

https://127.0.0.1:8983/solr/techproducts/config/requestHandler

V2 API

https://127.0.0.1:8983/api/collections/techproducts/config/requestHandler

出力は、solrconfig.xml で定義された各リクエストハンドラー、Solr によって暗黙的に定義されたリクエストハンドラー、およびこの Config API で定義され configoverlay.json に保存されたリクエストハンドラーの詳細になります。暗黙的なリクエストハンドラーの設定を確認するには、リクエストに expandParams=true を追加してください。このコマンドの使用例については、上記にリンクされている暗黙的なリクエストハンドラーのドキュメントを参照してください。

パスパラメーターとして追加できる最上位セクションは、queryrequestHandlersearchComponentupdateHandlerqueryResponseWriterinitParamsznodeVersionlistenerdirectoryFactoryindexConfig、および codecFactory です。

リクエストを最上位セクション内の単一コンポーネントにさらに制限するには、componentName リクエストパラメーターを使用します。

例として、/select リクエストハンドラーの設定を返すには、

V1 API

https://127.0.0.1:8983/solr/techproducts/config/requestHandler?componentName=/select

V2 API

https://127.0.0.1:8983/api/collections/techproducts/config/requestHandler?componentName=/select

このコマンドの出力は次のようになります。

{
  "config":{"requestHandler":{"/select":{
        "name": "/select",
        "class": "solr.SearchHandler",
        "defaults":{
          "echoParams": "explicit",
          "rows":10
        }}}}
}

最上位セクション内のオブジェクトに制限する機能は、リクエストハンドラー (requestHandler)、検索コンポーネント (searchComponent)、およびレスポンスライター (queryResponseWriter) に限定されます。

設定を変更するコマンド

この API は、POST リクエストで特定のコマンドを使用して、configoverlay.json に追加または変更するプロパティまたはプロパティのタイプを Solr に指示します。コマンドは、プロパティまたはコンポーネントを追加または変更するデータとともに渡されます。

変更のための Config API コマンドは、3 つのタイプに分類され、それぞれ solrconfig.xml 内の特定のデータ構造を操作します。これらのタイプは次のとおりです。

共通プロパティのコマンド

共通プロパティは、Solr インスタンスで頻繁にカスタマイズされるプロパティです。これらは 2 つのコマンドで操作されます。

  • set-property: 既知のプロパティを設定します。プロパティの名前は事前定義されており、固定されています。プロパティがすでに設定されている場合、このコマンドは以前の設定を上書きします。

  • unset-property: set-property コマンドを使用して設定されたプロパティを削除します。

set-property および unset-property で設定できるプロパティは事前定義されており、以下にリストされています。これらのプロパティの名前は、solrconfig.xml にある XML パスから派生しています。

更新ハンドラーの設定

これらの設定のデフォルト値と許容値については、コミットとトランザクションログを参照してください。

  • updateHandler.autoCommit.maxDocs

  • updateHandler.autoCommit.maxTime

  • updateHandler.autoCommit.openSearcher

  • updateHandler.autoSoftCommit.maxDocs

  • updateHandler.autoSoftCommit.maxTime

  • updateHandler.commitWithin.softCommit

クエリ設定

これらの設定のデフォルト値と許容値については、キャッシュとクエリウォーミングを参照してください。

キャッシュとキャッシュサイズ

  • query.filterCache.class

  • query.filterCache.size

  • query.filterCache.initialSize

  • query.filterCache.autowarmCount

  • query.filterCache.maxRamMB

  • query.filterCache.regenerator

  • query.queryResultCache.class

  • query.queryResultCache.size

  • query.queryResultCache.initialSize

  • query.queryResultCache.autowarmCount

  • query.queryResultCache.maxRamMB

  • query.queryResultCache.regenerator

  • query.documentCache.class

  • query.documentCache.size

  • query.documentCache.initialSize

  • query.documentCache.autowarmCount

  • query.documentCache.regenerator

  • query.fieldValueCache.class

  • query.fieldValueCache.size

  • query.fieldValueCache.initialSize

  • query.fieldValueCache.autowarmCount

  • query.fieldValueCache.regenerator

クエリのサイズとウォーミング

  • query.maxBooleanClauses

  • query.enableLazyFieldLoading

  • query.useFilterForSortedQuery

  • query.queryResultWindowSize

  • query.queryResultMaxDocCached

クエリサーキットブレーカー

詳細については、サーキットブレーカーを参照してください。

  • query.memEnabled

  • query.memThreshold

RequestDispatcher の設定

これらの設定のデフォルト値と許容値については、RequestDispatcher を参照してください。

  • requestDispatcher.handleSelect

  • requestDispatcher.requestParsers.multipartUploadLimitInKB

  • requestDispatcher.requestParsers.formdataUploadLimitInKB

  • requestDispatcher.requestParsers.addHttpRequestToContext

共通プロパティの例

これらのプロパティの 1 つを変更または追加するコマンドを構築するには、次のパターンに従います。

{"set-property":{"<property>": "<value>"}}

updateHandler.autoCommit.maxTime を増やすリクエストは次のようになります。

V1 API

curl -X POST -H 'Content-type: application/json' -d '{"set-property":{"updateHandler.autoCommit.maxTime":15000}}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type: application/json' -d '{"set-property":{"updateHandler.autoCommit.maxTime":15000}}' https://127.0.0.1:8983/api/collections/techproducts/config

config/overlay エンドポイントを使用して、プロパティが configoverlay.json に追加されたことを確認できます。

V1 API

curl https://127.0.0.1:8983/solr/techproducts/config/overlay?omitHeader=true

V2 API

curl https://127.0.0.1:8983/api/collections/techproducts/config/overlay?omitHeader=true

出力

{
  "overlay": {
    "znodeVersion": 1,
    "props": {
      "updateHandler": {
        "autoCommit": {"maxTime": 15000}
      }
}}}

プロパティを削除するには

V1 API

curl -X POST -H 'Content-type: application/json' -d '{"unset-property": "updateHandler.autoCommit.maxTime"}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type: application/json' -d '{"unset-property": "updateHandler.autoCommit.maxTime"}' https://127.0.0.1:8983/api/collections/techproducts/config

ハンドラーとコンポーネントのコマンド

リクエストハンドラー、検索コンポーネント、およびその他のタイプのローカライズされた Solr コンポーネント (クエリパーサー、更新プロセッサーなど) は、変更されるコンポーネントのタイプに固有のコマンドを使用して追加、更新、および削除できます。

構文は各ケースで似ています: add-<_component-name_>update-<_component-name_>、および delete-<_component-name_>。コマンド名は大文字と小文字を区別しないため、Add-RequestHandlerADD-REQUESTHANDLER、および add-requesthandler は同等です。

各ケースで、add- コマンドは configoverlay.json に新しい設定を追加します。これにより、solrconfig.xml 内のコンポーネントの他の設定が上書きされます。

update- コマンドは configoverlay.json 内の既存の設定を上書きします。

delete- コマンドは configoverlay.json から設定を削除します。

configoverlay.json から削除された設定は、solrconfig.xml に重複して存在する場合でも、solrconfig.xml からは削除されません。

利用可能なコマンドの完全なリストは以下に続きます。

コンポーネントの基本コマンド

これらのコマンドは最も一般的に使用されます。

  • add-requesthandler

  • update-requesthandler

  • delete-requesthandler

  • add-searchcomponent

  • update-searchcomponent

  • delete-searchcomponent

  • add-initparams

  • update-initparams

  • delete-initparams

  • add-queryresponsewriter

  • update-queryresponsewriter

  • delete-queryresponsewriter

コンポーネントの高度なコマンド

これらのコマンドを使用すると、Solr へのより高度なカスタマイズを登録できます。

  • add-queryparser

  • update-queryparser

  • delete-queryparser

  • add-valuesourceparser

  • update-valuesourceparser

  • delete-valuesourceparser

  • add-transformer

  • update-transformer

  • delete-transformer

  • add-updateprocessor

  • update-updateprocessor

  • delete-updateprocessor

  • add-queryconverter

  • update-queryconverter

  • delete-queryconverter

  • add-listener

  • update-listener

  • delete-listener

  • add-expressible

  • update-expressible

  • delete-expressible

ハンドラーとコンポーネントのコマンドの例

リクエストハンドラーを作成するには、add-requesthandler コマンドを使用できます。

curl -X POST -H 'Content-type:application/json'  -d '{
  "add-requesthandler": {
    "name": "/mypath",
    "class": "solr.DumpRequestHandler",
    "defaults":{ "x": "y" ,"a": "b", "rows":10 },
    "useParams": "x"
  }
}' https://127.0.0.1:8983/solr/techproducts/config

V1 API

curl -X POST -H 'Content-type:application/json' -d '{
  "add-requesthandler": {
    "name": "/mypath",
    "class": "solr.DumpRequestHandler",
    "defaults": { "x": "y" ,"a": "b", "rows":10 },
    "useParams": "x"
  }
}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{
  "add-requesthandler": {
    "name": "/mypath",
    "class": "solr.DumpRequestHandler",
    "defaults": { "x": "y" ,"a": "b", "rows":10 },
    "useParams": "x"
  }
}' https://127.0.0.1:8983/api/collections/techproducts/config

新しいリクエストハンドラーにコールして、登録されているかどうかを確認します。

$ curl https://127.0.0.1:8983/solr/techproducts/mypath?omitHeader=true

次の出力が表示されるはずです。

{
  "params":{
    "indent": "true",
    "a": "b",
    "x": "y",
    "rows": "10"},
  "context":{
    "webapp": "/solr",
    "path": "/mypath",
    "httpMethod": "GET"}}

リクエストハンドラーを更新するには、update-requesthandler コマンドを使用する必要があります。

V1 API

curl -X POST -H 'Content-type:application/json' -d '{
  "update-requesthandler": {
    "name": "/mypath",
    "class": "solr.DumpRequestHandler",
    "defaults": {"x": "new value for X", "rows": "20"},
    "useParams": "x"
  }
}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{
  "update-requesthandler": {
    "name": "/mypath",
    "class": "solr.DumpRequestHandler",
    "defaults": {"x": "new value for X", "rows": "20"},
    "useParams": "x"
  }
}' https://127.0.0.1:8983/api/collections/techproducts/config

2 番目の例として、別のリクエストハンドラーを作成します。今回は、定義の一部として「terms」コンポーネントを追加します。

V1 API

curl -X POST -H 'Content-type:application/json' -d '{
  "add-requesthandler": {
    "name": "/myterms",
    "class": "solr.SearchHandler",
    "defaults": {"terms": true, "distrib":false},
    "components": ["terms"]
  }
}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{
  "add-requesthandler": {
    "name": "/myterms",
    "class": "solr.SearchHandler",
    "defaults": {"terms": true, "distrib":false},
    "components": ["terms"]
  }
}' https://127.0.0.1:8983/api/collections/techproducts/config

最後に、delete-requesthandler コマンドを使用してリクエストハンドラーを削除します。

V1 API

curl -X POST -H 'Content-type:application/json' -d '{
  "delete-requesthandler": "/myterms"
}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{
  "delete-requesthandler": "/myterms"
}' https://127.0.0.1:8983/api/collections/techproducts/config

ユーザー定義プロパティのコマンド

Solr では、プレースホルダー形式 ${variable_name:default_val} を使用して solrconfig.xml をテンプレート化できます。システムプロパティ (例: -Dvariable_name= my_customvalue) を使用して値を設定できます。これらのコマンドを使用すると、実行時にも同じことを実現できます。

  • set-user-property: ユーザー定義プロパティを設定します。プロパティがすでに設定されている場合、このコマンドは以前の設定を上書きします。

  • unset-user-property: ユーザー定義プロパティを削除します。

リクエストの構造は、"command":{"variable_name": "property_value"} の形式で、他のコマンドを使用するリクエストの構造に似ています。必要に応じて、一度に複数の変数を追加できます。

ユーザー定義プロパティの詳細については、core.properties でのユーザー定義プロパティのセクションを参照してください。

このタイプのコマンドの使用例については、以下のユーザー定義プロパティの作成と更新のセクションも参照してください。

ユーザー定義プロパティの作成と更新

このコマンドは、ユーザープロパティを設定します。

V1 API

curl -X POST -H 'Content-type:application/json' -d '{"set-user-property": {"variable_name": "some_value"}}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{"set-user-property": {"variable_name": "some_value"}}' https://127.0.0.1:8983/api/collections/techproducts/config

繰り返しになりますが、/config/overlay エンドポイントを使用して、変更が行われたことを確認できます。

V1 API

curl https://127.0.0.1:8983/solr/techproducts/config/overlay?omitHeader=true

V2 API

curl https://127.0.0.1:8983/api/collections/techproducts/config/overlay?omitHeader=true

次のような出力が表示されるはずです。

{"overlay":{
   "znodeVersion":5,
   "userProps":{
     "variable_name": "some_value"}}
}

変数を設定解除するには、次のようなコマンドを発行します。

V1 API

curl -X POST -H 'Content-type:application/json' -d '{"unset-user-property": "variable_name"}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{"unset-user-property": "variable_name"}' https://127.0.0.1:8983/api/collections/techproducts/config

updateRequestProcessorChain 要素

Config API では、updateRequestProcessorChain 要素を作成または編集することはできません。ただし、updateProcessor エントリを作成し、名前を使用してチェーンを作成することは可能です。

例:

V1 API

curl -X POST -H 'Content-type:application/json' -d '{"add-updateprocessor":
  {"name": "firstFld",
  "class": "solr.FirstFieldValueUpdateProcessorFactory",
  "fieldName": "test_s"}
}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{"add-updateprocessor":
  {"name": "firstFld",
  "class": "solr.FirstFieldValueUpdateProcessorFactory",
  "fieldName": "test_s"}
}' https://127.0.0.1:8983/api/collections/techproducts/config

特定の更新プロセッサー processor=firstFld を呼び出す updateRequestProcessorChain でパラメーターを追加することで、リクエストで直接これを使用できます。

solrconfig.xml プロパティを JSON にマッピングする方法

この API を使用すると、solrconfig.xml で定義されたプロパティの JSON 表現が生成されます。API でプロパティをどのように表現する必要があるかを理解するために、いくつかの例を見てみましょう。

solrconfig.xml でのリクエストハンドラーは次のようになります。

<requestHandler name="/query" class="solr.SearchHandler">
  <lst name="defaults">
    <str name="echoParams">explicit</str>
    <int name="rows">10</str>
  </lst>
</requestHandler>

Config API で定義された同じリクエストハンドラーは次のようになります。

{
  "add-requesthandler":{
    "name": "/query",
    "class": "solr.SearchHandler",
    "defaults":{
      "echoParams": "explicit",
      "rows": 10
    }
  }
}

solrconfig.xml の QueryElevationComponent searchComponent は次のようになります。

<searchComponent name="elevator" class="solr.QueryElevationComponent" >
  <str name="queryFieldType">string</str>
  <str name="config-file">elevate.xml</str>
</searchComponent>

Config API を使用した同じ searchComponent は次のようになります。

{
  "add-searchcomponent":{
    "name": "elevator",
    "class": "solr.QueryElevationComponent",
    "queryFieldType": "string",
    "config-file": "elevate.xml"
  }
}

Config API を使用して searchComponent を削除する

{
  "delete-searchcomponent": "elevator"
}

シンプルなハイライターは、solrconfig.xml では次のようになります (例はスペースを節約するために切り詰められています)。

<searchComponent class="solr.HighlightComponent" name="highlight">
    <highlighting>
      <fragmenter name="gap"
                  default="true"
                  class="solr.highlight.GapFragmenter">
        <lst name="defaults">
          <int name="hl.fragsize">100</int>
        </lst>
      </fragmenter>

      <formatter name="html"
                 default="true"
                 class="solr.highlight.HtmlFormatter">
        <lst name="defaults">
          <str name="hl.simple.pre"><![CDATA[<em>]]></str>
          <str name="hl.simple.post"><![CDATA[</em>]]></str>
        </lst>
      </formatter>

      <encoder name="html" class="solr.highlight.HtmlEncoder" />
...
    </highlighting>

Config API を使用した同じハイライター

{
    "add-searchcomponent": {
        "name": "highlight",
        "class": "solr.HighlightComponent",
        "": {
            "gap": {
                "default": "true",
                "name": "gap",
                "class": "solr.highlight.GapFragmenter",
                "defaults": {
                    "hl.fragsize": 100
                }
            }
        },
        "html": [{
            "default": "true",
            "name": "html",
            "class": "solr.highlight.HtmlFormatter",
            "defaults": {
                "hl.simple.pre": "before-",
                "hl.simple.post": "-after"
            }
        }, {
            "name": "html",
            "class": "solr.highlight.HtmlEncoder"
        }]
    }
}

solrconfig.xml で autoCommit プロパティを設定する

<autoCommit>
  <maxTime>15000</maxTime>
  <openSearcher>false</openSearcher>
</autoCommit>

Config API で同じプロパティを定義する

{
  "set-property": {
    "updateHandler.autoCommit.maxTime":15000,
    "updateHandler.autoCommit.openSearcher":false
  }
}

Config API のコンポーネントの名前

Config APIは、常に名前で任意のコンポーネントの設定変更を許可します。ただし、listenerinitParamsなど、solrconfig.xmlで名前を必要としない設定もあります。configoverlay.json内で同じ項目のupdatedeleteをできるようにするため、name属性が必須になります。

Config APIの仕組み

SolrCloudを使用する場合、すべてのコアは、そのコアで使用されているconfigsetのZooKeeperディレクトリを監視します。同じノード内で同じconfigsetを使用する複数のコアがある場合、ZooKeeperの監視は1つだけ使用されます。

ヒント

ユーザー管理のクラスターまたはシングルノードインストールでは、監視はありません(ZooKeeperが実行されていないため)。

たとえば、configset 'myconf'がコアで使用されている場合、ノードは/configs/myconfを監視します。APIを通じて実行されるすべての書き込み操作は、ディレクトリを「タッチ」し、すべてのウォッチャーに通知されます。すべてのコアは、スキーマファイル、solrconfig.xml、またはconfigoverlay.jsonznodeのバージョンを比較して変更されたかどうかを確認します。いずれかが変更された場合、コアはリロードされます。

params.jsonが変更された場合、paramsオブジェクトはコアのリロードなしで更新されます(params.jsonの詳細については、リクエストパラメータAPIを参照してください)。

空のコマンド

空のコマンドが/configエンドポイントに送信されると、このconfigsetを使用しているすべてのコアで監視がトリガーされます。例:

V1 API

curl -X POST -H 'Content-type:application/json' -d '{}' https://127.0.0.1:8983/solr/techproducts/config

V2 API

curl -X POST -H 'Content-type:application/json' -d '{}' https://127.0.0.1:8983/api/collections/techproducts/config

ディレクトリを「タッチ」せずにファイルを直接編集しても、すべてのノードに表示されるわけではありません

コンポーネントは、SolrCore#registerConfListener()を使用してリスナーを登録することにより、configsetの「タッチ」イベントを監視できます。

設定変更のリスニング

任意のコンポーネントは、以下を使用してリスナーを登録できます。

SolrCore#addConfListener(Runnable listener)

設定変更の通知を受け取ります。変更されたファイルがコアのリロードを引き起こす場合(つまり、configoverlay.xmlまたはスキーマ)、これはあまり役に立ちません。コンポーネントはこれを使用して、関心のあるファイルをリロードできます。