Search code examples
solr

Solr upload schema.xml viw REST API


I am probably blind,but I don't see it in the documentation. What is the correct url and curl request of update managed schema.xml file?

I had tried:

curl -X POST -d @schema.xml -H "Content-Type: text/xml" http://<SOLR>:8983/solr/<CORE>/schema/files/schema.xml

curl -X POST -d @schema.xml -H "Content-Type: text/xml" http://<SOLR>:8983/solr/<CORE>/schema

curl -X POST -d @schema.xml -H "Content-Type: text/xml" http://<SOLR>:8983/solr/<CORE>/schema/schema.xml

All with PUT method too.

version of Solr: 5.5.2


Solution

  • As far as I know, there is no "replace the complete schema" command for the Schema API. The managed schema is updated based on a set of commands through the API:

    POST /collection/schema

    To add, remove or replace fields, dynamic field rules, copy field rules, or new field types, you can send a POST request to the /collection/schema/ endpoint with a sequence of commands to perform the requested actions. The following commands are supported:

    add-field: add a new field with parameters you provide.

    delete-field: delete a field.

    replace-field: replace an existing field with one that is differently configured.

    add-dynamic-field: add a new dynamic field rule with parameters you provide.

    delete-dynamic-field: delete a dynamic field rule.

    replace-dynamic-field: replace an existing dynamic field rule with one that is differently configured.

    add-field-type: add a new field type with parameters you provide.

    delete-field-type: delete a field type.

    replace-field-type: replace an existing field type with one that is differently configured.

    add-copy-field: add a new copy field rule.

    delete-copy-field: delete a copy field rule.

    To do what you want, you probably want to replace the managed-schema file yourself and then restart solr or reload the core yourself:

    Why is hand editing of the managed schema discouraged?

    The file named "managed-schema" in the example configurations may include a note that recommends never hand-editing the file. Before the Schema API existed, such edits were the only way to make changes to the schema, and users may have a strong desire to continue making changes this way. The reason that this is discouraged is because hand-edits of the schema may be lost if the Schema API described here is later used to make a change, unless the core or collection is reloaded or Solr is restarted before using the Schema API. If care is taken to always reload or restart after a manual edit, then there is no problem at all with doing those edits.