You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by "Steve Rowe (Confluence)" <co...@apache.org> on 2013/07/23 07:33:00 UTC

[CONF] Apache Solr Reference Guide > Schema API

Space: Apache Solr Reference Guide (https://cwiki.apache.org/confluence/display/solr)
Page: Schema API (https://cwiki.apache.org/confluence/display/solr/Schema+API)

Change Comment:
---------------------------------------------------------------------
Added Solr 4.4 schema update capabilities

Edited by Steve Rowe:
---------------------------------------------------------------------

The Solr schema API allows using a REST API to get information about the {{schema.xml}} for each collection (or core for standalone Solr), including defined field types, fields, dynamic fields, and copy field declarations. In Solr 4.2 and 4.3, it only allows GET (read-only) access, but in Solr 4.4, new fields and copyField directives may be added to the schema.  Future Solr releases will extend this functionality to allow more schema elements to be updated. 

To enable schema modification with this API, the schema will need to be managed and mutable. See the section [solr:Managed Schema Definition in SolrConfig] for more information.

The API allows two output modes for all calls: JSON or XML. When requesting the complete schema, there is another output mode which is XML modeled after the schema.xml file itself. 

The base address for the API is {{http://<host>:<port>/<context-path>}}, where {{<context-path>}} is usually {{solr}}, though you may have configured it differently.  Example base address: {{http://localhost:8983/solr}}.

In the API entry points and example URLs below, you may alternatively specify a Solr _core_ name where it says _collection_.  

{toc} 

h2. API Entry Points 

{{/_collection_/schema}}: [retrieve|#api1] the entire schema
{{/_collection_/schema/fields}}: [retrieve information|#api2] about all defined fields, or [create|#api14] new fields with optional copyField directives
{{/_collection_/schema/fields/_name_}}: [retrieve information|#api3] about a named field, or [create|#api15] a new named field with optional copyField directives
{{/_collection_/schema/dynamicfields}}: [retrieve information|#api4] about dynamic field rules
{{/_collection_/schema/dynamicfields/_name_}}: [retrieve information|#api5] about a named dynamic rule
{{/_collection_/schema/fieldtypes}}: [retrieve information|#api6] about field types
{{/_collection_/schema/fieldtypes/_name_}}: [retrieve information|#api7] about a named field type
{{/_collection_/schema/copyfields}}: [retrieve information|#api8] about copy fields, or [create|#api16] new copyField directives
{{/_collection_/schema/name}}: [retrieve|#api9] the schema name
{{/_collection_/schema/version}}: [retrieve|#api10] the schema version
{{/_collection_/schema/uniquekey}}: [retrieve|#api11] the defined uniqueKey
{{/_collection_/schema/similarity}}: [retrieve|#api12] the global similarity definition
{{/_collection_/schema/solrqueryparser/defaultoperator}}: [retrieve|#api13] the default operator

{anchor:api1} 

h2. Retrieve the Entire Schema

{{GET /_collection_/schema}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

|| Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json*, *xml* or *schema.xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include all fields, field types, dynamic rules and copy field rules. The schema name and version are also included.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the entire schema in JSON.

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema?wt=json
{code}

Get the entire schema in XML.

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema?wt=xml
{code}

Get the entire schema in "schema.xml" format.

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema?wt=schema.xml
{code}

*Output* 
The samples below have been truncated to only show a few snippets of the output.

Example output in JSON:
{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":5},
  "schema":{
    "name":"example",
    "version":1.5,
    "uniqueKey":"id",
    "fieldTypes":[{
        "name":"alphaOnlySort",
        "class":"solr.TextField",
        "sortMissingLast":true,
        "omitNorms":true,
        "analyzer":{
          "tokenizer":{
            "class":"solr.KeywordTokenizerFactory"},
          "filters":[{
              "class":"solr.LowerCaseFilterFactory"},
            {
              "class":"solr.TrimFilterFactory"},
            {
              "class":"solr.PatternReplaceFilterFactory",
              "replace":"all",
              "replacement":"",
              "pattern":"([^a-z])"}]}},
...
    "fields":[{
        "name":"_version_",
        "type":"long",
        "indexed":true,
        "stored":true},
      {
        "name":"author",
        "type":"text_general",
        "indexed":true,
        "stored":true},
      {
        "name":"cat",
        "type":"string",
        "multiValued":true,
        "indexed":true,
        "stored":true},
      {
        "name":"category",
        "type":"text_general",
        "indexed":true,
        "stored":true},
...
    "copyFields":[{
        "source":"author",
        "dest":"text"},
      {
        "source":"cat",
        "dest":"text"},
      {
        "source":"content",
        "dest":"text"},
      {
        "source":"content_type",
        "dest":"text"},
...
      {
        "source":"author",
        "dest":"author_s"}]}}
{code} 

Example output in XML:

{code:language=xml|borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">5</int>
</lst>
<lst name="schema">
  <str name="name">example</str>
  <float name="version">1.5</float>
  <str name="uniqueKey">id</str>
  <arr name="fieldTypes">
    <lst>
      <str name="name">alphaOnlySort</str>
      <str name="class">solr.TextField</str>
      <bool name="sortMissingLast">true</bool>
      <bool name="omitNorms">true</bool>
      <lst name="analyzer">
        <lst name="tokenizer">
          <str name="class">solr.KeywordTokenizerFactory</str>
        </lst>
        <arr name="filters">
          <lst>
            <str name="class">solr.LowerCaseFilterFactory</str>
          </lst>
          <lst>
            <str name="class">solr.TrimFilterFactory</str>
          </lst>
          <lst>
            <str name="class">solr.PatternReplaceFilterFactory</str>
            <str name="replace">all</str>
            <str name="replacement"/>
            <str name="pattern">([^a-z])</str>
          </lst>
        </arr>
      </lst>
    </lst>
...
    <lst>
      <str name="source">author</str>
      <str name="dest">author_s</str>
    </lst>
  </arr>
</lst>
</response>
{code}

Example output in schema.xml format:

{code:language=xml|borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<schema name="example" version="1.5">
  <uniqueKey>id</uniqueKey>
  <types>
    <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">
      <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.TrimFilterFactory"/>
        <filter class="solr.PatternReplaceFilterFactory" replace="all" replacement="" pattern="([^a-z])"/>
      </analyzer>
    </fieldType>
...
  <copyField source="url" dest="text"/>
  <copyField source="price" dest="price_c"/>
  <copyField source="author" dest="author_s"/>
</schema>
{code}


{anchor:api2}

h2. List Fields

{{GET /_collection_/schema/fields}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include each field and any defined configuration for each field. The defined configuration can vary for each field, but will minimally include the field {{name}}, the {{type}}, if it is {{indexed}} and if it is {{stored}}. If {{multiValued}} is defined as either true or false (most likely true), that will also be shown. See the section [solr:Defining Fields] for more information about each parameter.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get a list of all fields.

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema/fields?wt=json
{code}

*Output* 
The sample output below has been truncated to only show a few fields.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "fields": [
        {
            "indexed": true, 
            "name": "_version_", 
            "stored": true, 
            "type": "long"
        }, 
        {
            "indexed": true, 
            "name": "author", 
            "stored": true, 
            "type": "text_general"
        }, 
        {
            "indexed": true, 
            "multiValued": true, 
            "name": "cat", 
            "stored": true, 
            "type": "string"
        }, 
        {
            "indexed": true, 
            "name": "category", 
            "stored": true, 
            "type": "text_general"
        } 
...
    ], 
    "responseHeader": {
        "QTime": 1, 
        "status": 0
    }
}
{code} 

{anchor:api3} 

h2. List a Specific Field

{{GET /_collection_/schema/fields/_fieldname_}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |
| fieldname | The specific field name. |   

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include each field and any defined configuration for the field. The defined configuration can vary for a field, but will minimally include the field {{name}}, the {{type}}, if it is {{indexed}} and if it is {{stored}}. If {{multiValued}} is defined as either true or false (most likely true), that will also be shown. See the section [solr:Defining Fields] for more information about each parameter.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the 'author' field.

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema/fields/author?wt=json
{code}

*Output* 

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "field": {
        "indexed": true, 
        "name": "author", 
        "stored": true, 
        "type": "text_general"
    }, 
    "responseHeader": {
        "QTime": 2, 
        "status": 0
    }
}
{code}

{anchor:api4} 

h2. List Dynamic Fields

{{GET /_collection_/schema/dynamicfields}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description ||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include each dynamic field rule and the defined configuration for each rule. The defined configuration can vary for each rule, but will minimally include the dynamic field {{name}}, the {{type}}, if it is {{indexed}} and if it is {{stored}}. See the section [solr:Dynamic Fields] for more information about each parameter.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get a list of all dynamic field declarations

{code:language=none|borderStyle=solid|borderColor=#666666}
curl http://localhost:8983/solr/collection1/schema/dynamicfields?wt=json
{code}

*Output* 
The sample output below has been truncated.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "dynamicFields": [
        {
            "indexed": true, 
            "name": "*_coordinate", 
            "stored": false, 
            "type": "tdouble"
        }, 
        {
            "multiValued": true, 
            "name": "ignored_*", 
            "type": "ignored"
        }, 
        {
            "name": "random_*", 
            "type": "random"
        }, 
        {
            "indexed": true, 
            "multiValued": true, 
            "name": "attr_*", 
            "stored": true, 
            "type": "text_general"
        }, 
        {
            "indexed": true, 
            "multiValued": true, 
            "name": "*_txt", 
            "stored": true, 
            "type": "text_general"
        } 
...
    ], 
    "responseHeader": {
        "QTime": 1, 
        "status": 0
    }
}
{code}

{anchor:api5} 

h2. List a Specific Dynamic Field Rule

{{GET /_collection_/schema/dynamicfields/_name_}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |
| name | The name of the dynamic field rule. |

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include the requested dynamic field rule and any defined configuration for the rule. The defined configuration can vary for each rule, but will minimally include the dynamic field {{name}}, the {{type}}, if it is {{indexed}} and if it is {{stored}}. See the section [solr:Dynamic Fields] for more information about each parameter.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the details of the "\*_s" rule.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/dynamicfields/*_s?wt=json
{code}

*Output* 
{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "dynamicfield": {
        "indexed": true, 
        "name": "*_s", 
        "stored": true, 
        "type": "string"
    }, 
    "responseHeader": {
        "QTime": 1, 
        "status": 0
    }
}
{code}

{anchor:api6} 

h2. List Field Types

{{GET /_collection_/schema/fieldtypes}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include each field type and any defined configuration for the type. The defined configuration can vary for each type, but will minimally include the field type {{name}} and the {{class}}. If query or index analyzers, tokenizers, or filters are defined, those will also be shown with other defined parameters. See the section [solr:Solr Field Types] for more information about how to configure various types of fields.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get a list of all field types.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fieldtypes?wt=json
{code}

*Output* 
The sample output below has been truncated to show a few different field types from different parts of the list.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "fieldTypes": [
        {
            "analyzer": {
                "class": "solr.TokenizerChain", 
                "filters": [
                    {
                        "class": "solr.LowerCaseFilterFactory"
                    }, 
                    {
                        "class": "solr.TrimFilterFactory"
                    }, 
                    {
                        "class": "solr.PatternReplaceFilterFactory", 
                        "pattern": "([^a-z])", 
                        "replace": "all", 
                        "replacement": ""
                    }
                ], 
                "tokenizer": {
                    "class": "solr.KeywordTokenizerFactory"
                }
            }, 
            "class": "solr.TextField", 
            "dynamicFields": [], 
            "fields": [], 
            "name": "alphaOnlySort", 
            "omitNorms": true, 
            "sortMissingLast": true
        }, 
...
        {
            "class": "solr.TrieFloatField", 
            "dynamicFields": [
                "*_fs", 
                "*_f"
            ], 
            "fields": [
                "price", 
                "weight"
            ], 
            "name": "float", 
            "positionIncrementGap": "0", 
            "precisionStep": "0"
        }, 
...
        {
            "class": "solr.TrieIntField", 
            "dynamicFields": [
                "*_is", 
                "*_i"
            ], 
            "fields": [
                "popularity"
            ], 
            "name": "int", 
            "positionIncrementGap": "0", 
            "precisionStep": "0"
        }, 
        {
            "class": "solr.LatLonType", 
            "dynamicFields": [
                "*_p"
            ], 
            "fields": [
                "store"
            ], 
            "name": "location", 
            "subFieldSuffix": "_coordinate"
        }, 
...
        {
            "class": "solr.TrieLongField", 
            "dynamicFields": [
                "*_tl"
            ], 
            "fields": [], 
            "name": "tlong", 
            "positionIncrementGap": "0", 
            "precisionStep": "8"
        }
    ], 
    "responseHeader": {
        "QTime": 4, 
        "status": 0
    }
}
{code} 

{anchor:api7} 

h2. List a Specific Field Type

{{GET /_collection_/schema/fieldtypes/_name_}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |
| name | The name of the field type.|

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include each field type and any defined configuration for the type. The defined configuration can vary for each type, but will minimally include the field type {{name}} and the {{class}}. If query and/or index analyzers, tokenizers, or filters are defined, those will be shown with other defined parameters. See the section [solr:Solr Field Types] for more information about how to configure various types of fields.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get details of the "date" field type.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fieldtypes/date?wt=json
{code}

*Output* 
The sample output below has been truncated.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "fieldType": {
        "class": "solr.TrieDateField", 
        "dynamicFields": [
            "*_dts", 
            "*_dt"
        ], 
        "fields": [
            "last_modified"
        ], 
        "name": "date", 
        "positionIncrementGap": "0", 
        "precisionStep": "0"
    }, 
    "responseHeader": {
        "QTime": 2, 
        "status": 0
    }
}
{code}

{anchor:api8} 

h2. List Copy Fields

{{GET /_collection_/schema/copyfields}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include the {{source}} and {{dest}}ination of each copy field rule defined in {{schema.xml}}. For more information about copying fields, see the section [solr:Copying Fields].

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get a list of all copyfields.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fields?wt=json
{code}

*Output* 
The sample output below has been truncated to the first few copy definitions.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
    "copyFields": [
        {
            "dest": "text", 
            "source": "author"
        }, 
        {
            "dest": "text", 
            "source": "cat"
        }, 
        {
            "dest": "text", 
            "source": "content"
        }, 
        {
            "dest": "text", 
            "source": "content_type"
        }, 
...
    ], 
    "responseHeader": {
        "QTime": 3, 
        "status": 0
    }
}
{code}

{anchor:api9} 

h2. Show Schema Name

{{GET /_collection_/schema/name}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 
The output will be simply the name given to the schema.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the schema name.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/name?wt=json
{code}

*Output* 

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "name":"example"}
{code}

{anchor:api10} 

h2. Show the Schema Version

{{GET /_collection_/schema/version}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will simply be the schema version in use.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the schema version

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/version?wt=json
{code}

*Output* 

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":2},
  "version":1.5}
{code}

{anchor:api11} 

h2. List UniqueKey

{{GET /_collection_/schema/uniquekey}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include simply the field name that is defined as the uniqueKey for the index.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
List the uniqueKey.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/uniquekey?wt=json
{code}

*Output* 
The sample output below has been truncated to the first few copy definitions.

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":2},
  "uniqueKey":"id"}
{code}

{anchor:api12} 

h2. Show Global Similarity

{{GET /_collection_/schema/similarity}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include the class name of the global similarity defined (if any).

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get the similarity implementation.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/similarity?wt=json
{code}

*Output* 

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "similarity":{
    "class":"org.apache.solr.search.similarities.DefaultSimilarityFactory"}}
{code}

{anchor:api13} 

h2. Get the Default Query Operator

{{GET /_collection_/schema/solrqueryparser/defaultoperator}} 

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, JSON will be returned by default. |

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will include simply the default operator if none is defined by the user.

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*
Get a list of all copyfields.

{code:language=none|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/solrqueryparser/defaultoperator?wt=json
{code}

*Output* 

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":2},
  "defaultOperator":"OR"}
{code}

{anchor:api14} 

h2. Create new schema fields

{{POST /_collection_/schema/fields}} 

To enable schema modification, the schema will need to be managed and mutable. See the section [solr:Managed Schema Definition in SolrConfig] for more information.

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, json will be returned by default. |

*Request body*

Only JSON format is supported in the request body.  The JSON must contain an array of one or more new field specifications, each of which must include mappings for the new field's {{name}} and {{type}}.  All attributes specifiable on a schema {{<field name="..." ... />}} declaration may be specified here - see [solr:Defining Fields]. 

Additionally, {{copyField}} destination(s) may optionally be specified.  Note that each specified copyField destination must be an existing schema field (and not a dynamic field).  In particular, since the new fields specified in a new field creation request are defined all at once, you cannot specify a {{copyField}} that targets another new field in the same request - instead, you have to make two requests, defining the {{copyField}} destination in the first new field creation request, then specifying that field as a {{copyField}} destination in the second new field creation request.

The {{curl}} utility can provide the request body via its {{--data-binary}} option.

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will be the response header, containing a status code, and if there was a problem, an associated error message. 

Example output in the default JSON format:

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":8}}
{code}

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*

Add two new fields:

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fields -X POST -H 'Content-type:application/json' --data-binary '
[
    { 
        "name":"sell-by",
        "type":"tdate",
        "stored":true 
    },
    { 
        "name":"catchall",
        "type":"text_general",
        "stored":false
    }
]'
{code}

Add a third new field and copy it to the "catchall" field created above:

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fields -X POST -H 'Content-type:application/json' --data-binary '
[
    {
        "name":"department",
        "type":"string",
        "docValues":"true",
        "default":"no department",
        "copyFields": [ "catchall" ]
    }
]'
{code}

{anchor:api15}

h2. Create a new schema field with optional copyField directives

{{PUT /_collection_/schema/fields/_name_}} 

To enable schema modification, the schema will need to be managed and mutable. See the section [solr:Managed Schema Definition in SolrConfig] for more information.

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  
| name       | The new field name.            |

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, json will be returned by default. |

*Request body*

Only JSON format is supported in the request body.  The body must include a set of mappings, minimally for the new field's {{name}} and {{type}}.  All attributes specifiable on a schema {{<field name="..." ... />}} declaration may be specified here - see [solr:Defining Fields].

Additionally, {{copyField}} destination(s) may optionally be specified.  Note that each specified copyField destination must be an existing schema field (and not a dynamic field).

The {{curl}} utility can provide the request body via its {{--data-binary}} option.

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will be the response header, containing a status code, and if there was a problem, an associated error message. 

Example output in the default JSON format:

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":4}}
{code}

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*

Add a new field named "narrative":

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fields/narrative -X PUT -H 'Content-type:application/json' --data-binary '
{ 
    "type":"text_general",
    "stored":true ,
    "termVectors":true,
    "termPositions":true,
    "termOffsets":true
}'
{code}

Add a new field named "color" and copy it to two fields, named "narrative" and "catchall", which must already exist in the schema:

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/fields/color -X PUT -H 'Content-type:application/json' --data-binary '
{ 
    "type":"string",
    "stored":true,
    "copyFields": [ 
        "narrative", 
        "catchall" 
    ]
}'
{code}

:TODO:

{anchor:api16}

h2. Create new copyField directives

{{POST /_collection_/schema/copyfields}} 

To enable schema modification, the schema will need to be managed and mutable. See the section [solr:Managed Schema Definition in SolrConfig] for more information.

h4. {bgcolor:#FEECC4}{*}Input{*}{bgcolor} 

*Path Parameters* 

||Key || Description||
| collection | The collection (or core) name. |  

*Query Parameters* 

The query parameters can be added to the API request after a '?'.

|| Key || Type || Required || Default || Description || 
| wt | string | No | json | Defines the format of the response. The options are *json* or *xml*. If not specified, json will be returned by default. |

*Request body*

Only JSON format is supported in the request body.  The body must contain an array of zero or more copyField directives, each containing a mapping from {{source}} to the source field name, and from {{dest}} to an array of destination field name(s).

All referenced fields, both {{source}} and {{dest}}, must match existing schema fields or dynamic fields.

The {{curl}} utility can provide the request body via its {{--data-binary}} option.

h4. {bgcolor:#FEECC4}{*}Output{*}{bgcolor} 

*Output Content* 

The output will be the response header, containing a status code, and if there was a problem, an associated error message. 

Example output in the default JSON format:

{code:lanugage=javascript|borderStyle=solid|borderColor=#666666} 
{
  "responseHeader":{
    "status":0,
    "QTime":2}}
{code}

h4. {bgcolor:#FEECC4}{*}Examples{*}{bgcolor} 

*Input*

Copy the "affiliations" field to the "relations" field, and the "shelf" field to the "location" and "catchall" fields:

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/copyfields -X POST -H 'Content-type:application/json' --data-binary '
[
    { 
        "source":"affiliations",
        "dest": [
            "relations"
        ]
    },
    {
        "source":"shelf",
        "dest": [
            "location",
            "catchall"
        ]
    }
]'
{code}

Copy all fields names matching "finance_*" to the "*_s" dynamic field:

{code:language=javascript|borderStyle=solid|borderColor=#666666} 
curl http://localhost:8983/solr/collection1/schema/copyfields -X POST -H 'Content-type:application/json' --data-binary '
[
    { 
        "source":"finance_*",
        "dest": [
            "*_s"
        ]
    }
]'
{code}

h2. Related Topics

* [solr:Managed Schema Definition in SolrConfig]

{scrollbar}



Stop watching space: https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=solr
Change email notification preferences: https://cwiki.apache.org/confluence/users/editmyemailsettings.action