Differences between revisions 8 and 9
Revision 8 as of 2013-04-25 23:06:34
Size: 6970
Editor: SteveRowe
Comment:
Revision 9 as of 2013-04-25 23:16:39
Size: 7136
Editor: SteveRowe
Comment:
Deletions are marked like this. Additions are marked like this.
Line 55: Line 55:
<!> NOTE <!> Converting a SolrCloud configset's schema to managed, and adding fields to the schema, will affect all other collections that use the same configset.

Schema REST API

Reading schema information

<!> Solr 4.2

The Solr schema REST API provides information about the schema used by Solr cores and collections.

To query a schema for a particular core or collection, add the core or collection name after the context path (usually '/solr/'). E.g. to get all field declarations for collection1: http://localhost:8983/solr/collection1/schema/fields

Supported requests (URLs are for single/default core):

Schema component

HTTP method

Example URL

Supported query params

Default params

All requests

wt, indent

?wt=json&indent=on

All (entire schema) ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema

wt=json or wt=xml or wt=schema.xml

Fields

GET

http://localhost:8983/solr/schema/fields

fl, includeDynamic, showDefaults

&showDefaults=false

GET

http://localhost:8983/solr/schema/fields/name

includeDynamic, showDefaults

&showDefaults=false

Dynamic Fields

GET

http://localhost:8983/solr/schema/dynamicfields

fl, showDefaults

&showDefaults=false

GET

http://localhost:8983/solr/schema/dynamicfields/name

showDefaults

&showDefaults=false

Field Types

GET

http://localhost:8983/solr/schema/fieldtypes

showDefaults

&showDefaults=false

GET

http://localhost:8983/solr/schema/fieldtypes/name

showDefaults

&showDefaults=false

Copy Fields

GET

http://localhost:8983/solr/schema/copyfields

source.fl, dest.fl

Name ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema/name

Version ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema/version

Unique Key ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema/uniquekey

Global Similarity ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema/similarity

Default Query Operator ( <!> Solr 4.3)

GET

http://localhost:8983/solr/schema/solrqueryparser/defaultoperator

Adding fields to a schema

<!> Solr 4.4

Fields may be added to a schema if the field name(s) are not already in the schema, and if the field name(s) don't match any dynamicFields.

In order to enable schema modifications via the Schema REST API, the schema implementation must be declared as managed by Solr, that is, not to be manually edited. See SOLR-4658 for more information.

Further, the schema must be configured as mutable in order to make modifications to it.

Both of these schema features (managed and mutable) are configured via the <schemaFactory/> element in solrconfig.xml.

Here is an example declaring the schema to be managed and mutable, to be persisted in a resource named managed-schema, either as a file in the core's conf/ directory, or as a ZooKeeper znode in the configset used by the collection:

<schemaFactory class="ManagedIndexSchemaFactory">
  <bool name="mutable">true</bool>
  <str name="managedSchemaResourceName">managed-schema</str>
</schemaFactory>

The first time you load a core with the above declaration in the corresponding solrconfig.xml, it will convert the existing schema to managed format, persist the result to the resource you name in the configuration, and rename the original schema file by appending .bak to its name, e.g. schema.xml will be renamed to schema.xml.bak.

<!> NOTE <!> Converting a SolrCloud configset's schema to managed, and adding fields to the schema, will affect all other collections that use the same configset.

Supported requests - note that at present, only JSON is supported for the body of these requests:

Operation

HTTP method

Example URL

Example Body

Supported query params

Default params

All requests

wt, indent

?wt=json&indent=on

Add Multiple Fields

POST

http://localhost:8983/solr/schema/fields

[{"name":"newfield1","type":"text","stored":"false"},
  {"name":"newfield2","type":"text","stored":"false"}]

Add a Single Field

PUT

http://localhost:8983/solr/schema/fields/newfield

{"type":"text","stored":"false"} 

SchemaRESTAPI (last edited 2013-04-25 23:16:39 by SteveRowe)