Differences between revisions 14 and 15
Revision 14 as of 2013-07-10 14:12:51
Size: 9657
Editor: SteveRowe
Comment: Restructure the schema modification section
Revision 15 as of 2013-07-10 14:15:08
Size: 9656
Editor: SteveRowe
Comment:
Deletions are marked like this. Additions are marked like this.
Line 49: Line 49:
 * Specify Copy Field(s): !Copy Field directives may be added to the schema if both the source and all destination fields already exist in the schema. You can specify copyFields either as part of an add field(s) operation via a PUT or POST to {{{schema/fields}}}, or as an independent operation via a POST to {{{schema/copyfields}}}. See [[https://issues.apache.org/jira/browse/SOLR-5010|SOLR-5010]] for more information.  * Specify Copy Field(s): Copy Field directives may be added to the schema if both the source and all destination fields already exist in the schema. You can specify copyFields either as part of an add field(s) operation via a PUT or POST to {{{schema/fields}}}, or as an independent operation via a POST to {{{schema/copyfields}}}. See [[https://issues.apache.org/jira/browse/SOLR-5010|SOLR-5010]] for more information.

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&includeDynamic=false

GET

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

includeDynamic, showDefaults

&showDefaults=false&includeDynamic=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

Query params

param

description

showDefaults

include in the response all default property values from the associated field type, e.g. tokenized for solr.TextField

includeDynamic

if the "fl" param is specified, matching dynamic fields are included in the response and identified with the dynamicBase property; if the "fl" param is not specified, the "includeDynamic" query param is ignored

fl

restricts returned results to the value of this param, which can either be a single field or a comma- or space-separated list of fields

source.fl

copyField source field list - see the "fl" param description

dest.fl

copyField destination field list - see the "fl" param description

See CoreQueryParameters and CommonQueryParameters for descriptions of params not in the above table.

Modifying the schema

<!> Solr 4.4

Supported operations

  • Add field(s): Fields may be added to the schema if the field name(s) are not already in the schema, and if the field name(s) don't match any dynamicFields.
  • Specify Copy Field(s): Copy Field directives may be added to the schema if both the source and all destination fields already exist in the schema. You can specify copyFields either as part of an add field(s) operation via a PUT or POST to schema/fields, or as an independent operation via a POST to schema/copyfields. See SOLR-5010 for more information.

Required: Managed mutable schema

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 modifying the schema, will affect all other collections that use the same configset.

Supported requests

Note that at present, only JSON format 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 Field(s)

PUT

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

{"type":"text","stored":"false","copyFields":["target1",...]} 

POST

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

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

Specify Copy Field(s)

POST

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

[{"source":"sourceField","dest":["target1",...]}, ...] 

SchemaRESTAPI (last edited 2013-07-10 14:15:08 by SteveRowe)