SOLR5 Schema API__LUCENE/SOLR

Source: Internet
Author: User
Tags curl solr
1. Schema API

The schema API provides read and write access to each collection schema.
Read access to all schema elements is supported.
Fields (Fields), dynamic Fields, field types, and Copyfield can be added, deleted, or replaced. Future SOLR may support write operations on more schema elements.

Note: Once the schema has been modified, all data is indexed again.

To modify the schema through the API, the schema needs to be managed and mutable, see managed Schema configuration.
The API runs two output modes: JSON or XML.
When the schema is modified using the API, the core reload automatically occurs to take effect.

The basic address of the API is HTTP://<HOST>:<PORT>/SOLR/<COLLECTION_NAME&GT, such as Http://localhost:8983/solr/test

1.1 API Entry point (Entry Points)

/schema: Get schema, or modify schema to add, delete, or Replace fields, dynamic fields, copy fields, or field types.
/schema/fields: Gets all fields or specifies field information.
/schema/dynamicfields: Gets all dynamic fields or specifies field rule information.
/schema/copyfields: Get copy fields information.
/schema/fieldtypes: Gets all field types or specifies field type information.
/schema/name: Get schema name
/schema/version:
/schema/uniquekey:
/schema/similarity:
/schema/solrqueryparser/defaultoperator:

Cases:
Curl Http://localhost:8983/solr/test/schema #GET (-O)

1.2 Schema modification

Post requests to/collection/schema and submit a series of commands.

* Add-field: Use the parameters you provided to add a new field.
* Delete-field: Delete a field
* Replace-field: Replace existing fields with different configurations

* Add-dynamic-field: Add a new dynamic field using the parameters you provided.
* Delete-dynamic-field: Delete a dynamic field
* Replace-dynamic-field: Replace existing dynamic fields with different configurations

* Add-field-type: Use the parameters you provided to add a new field type.
* Delete-field-type: Delete a field type
* Replace-field-type: Replace existing field types with different configurations

* Add-copy-field: Add a new Copy field.
* Delete-copy-field: Delete a copy field

These commands can be executed in a specified order, either on a separate post or in the same post.

-Add a New Field

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field": {
"Name": "Sell-by",
"Type": "Tdate",
' Stored ': true}
} ' Http://localhost:8983/solr/test/schema

-Delete a Field
Curl-x post-h ' Content-type:application/json '--data-binary ' {
' Delete-field ': {' name ': ' Sell-by '}
} ' Http://localhost:8983/solr/test/schema


-Replace a Field

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Replace-field": {
"Name": "Sell-by",
' Type ': ' Date ',
' Stored ': false}
} ' Http://localhost:8983/solr/test/schema


-Add a Dynamic Field rule

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-dynamic-field": {
"Name": "*_s",
' Type ': ' String ',
' Stored ': true}
} ' Http://localhost:8983/solr/test/schema


-Delete a Dynamic Field rule

Curl-x post-h ' Content-type:application/json '--data-binary ' {
' Delete-dynamic-field ': {' name ': ' *_s '}
} ' Http://localhost:8983/solr/test/schema


-Replace a Dynamic Field rule

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Replace-dynamic-field": {
"Name": "*_s",
"Type": "Text_general",
' Stored ': false}
} ' Http://localhost:8983/solr/test/schema


-Add a New Field Type

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field-type": {
"Name": "Mynewtxtfield",
"Class": SOLR. TextField ",
"Positionincrementgap": "100",
"Analyzer": {
"Charfilters": [{
"Class": SOLR. Patternreplacecharfilterfactory ",
"Replacement": "$1$1",
"Pattern": "([a-za-z]) \\\\1+"}],
"Tokenizer": {
"Class": SOLR. Whitespacetokenizerfactory "},
"Filters": [{
"Class": SOLR. Worddelimiterfilterfactory ",
' preserveoriginal ': ' 0 '}]}}
} ' Http://localhost:8983/solr/test/schema


Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field-type": {
"Name": "Mynewtextfield",
"Class": SOLR. TextField ",
"Indexanalyzer": {
"Tokenizer": {
"Class": SOLR. Pathhierarchytokenizerfactory ",
"Delimiter": "/"}},
"Queryanalyzer": {
"Tokenizer": {
"Class": SOLR. Keywordtokenizerfactory "}}}
} ' Http://localhost:8983/solr/test/schema


-Delete a Field Type

Curl-x post-h ' Content-type:application/json '--data-binary ' {
' Delete-field-type ': {' name ': ' Mynewtxtfield '}
} ' Http://localhost:8983/solr/test/schema


-Replace a Field Type

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Replace-field-type": {
"Name": "Mynewtxtfield",
"Class": SOLR. TextField ",
"Positionincrementgap": "100",
"Analyzer": {
"Tokenizer": {
"Class": SOLR. Standardtokenizerfactory "}}}
} ' Http://localhost:8983/solr/test/schema


-Add a New Copy Field rule

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-copy-field": {
"Source": "Shelf",
"Dest": ["Location", "Catchall"]}
} ' Http://localhost:8983/solr/test/schema


-Delete a Copy Field rule

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Delete-copy-field": {"source": "Shelf", "dest": "Location"}
} ' Http://localhost:8983/solr/test/schema


-Multiple commands in a post

APIs are transactional, and multiple commands either succeed at the same time or fail.

Several different syntaxes.

Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field-type": {
"Name": "Mynewtxtfield",
"Class": SOLR. TextField ",
"Positionincrementgap": "100",
"Analyzer": {
"Charfilters": [{
"Class": SOLR. Patternreplacecharfilterfactory ",
"Replacement": "$1$1",
"Pattern": "([a-za-z]) \\\\1+"}],
"Tokenizer": {
"Class": SOLR. Whitespacetokenizerfactory "},
"Filters": [{
"Class": SOLR. Worddelimiterfilterfactory ",
' preserveoriginal ': ' 0 '}]}},
"Add-field": {
"Name": "Sell-by",
"Type": "Mynewtxtfield",
' Stored ': true}
} ' Http://localhost:8983/solr/test/schema


Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field": {
"Name": "Shelf",
"Type": "Mynewtxtfield",
' Stored ': true},
"Add-field": {
"Name": "Location",
"Type": "Mynewtxtfield",
' Stored ': true},
"Add-copy-field": {
"Source": "Shelf",
"Dest": ["Location", "Catchall"]}
} ' Http://localhost:8983/solr/test/schema


Curl-x post-h ' Content-type:application/json '--data-binary ' {
"Add-field": [
{' Name ': ' Shelf ',
"Type": "Mynewtxtfield",
' Stored ': true},
{' name ': ' Location ',
"Type": "Mynewtxtfield",
' Stored ': true}]
} ' Http://localhost:8983/solr/test/schema


-Modify schema between replica sets
When run in Solrcloud mode, changes to one node are passed to all collections. You can pass a updatetimeoutsecs parameter,
To specify the number of seconds to wait for all replication nodes to confirm that this modification has been applied.


1.3 Getting schema information


-Retrieve The Entire Schema

Path parameters:
/collection/

Request Parameters:
Wt

Cases:
Curl Http://localhost:8983/solr/test/schema
Curl Http://localhost:8983/solr/test/schema?wt=json
Curl Http://localhost:8983/solr/test/schema?wt=xml
Curl Http://localhost:8983/solr/test/schema?wt=schema.xml


-List Fields

Path parameters:
/collection/fieldname

Request Parameters:
Wt=json/xml
Fl=
Includedynamic=false/true
Showdefaults=false/true

Cases:
Curl Http://localhost:8983/solr/test/schema/fields?wt=json

-List Dynamic Fields

Path parameters:
/collection/fieldname/

Request Parameters:
Wt=json/xml
Showdefaults=false/true

Cases:
Curl Http://localhost:8983/solr/test/schema/dynamicfields?wt=json

-List Field Types

Path parameters:
/collection/fieldname/

Request Parameters:
Wt=json/xml
Showdefaults=false/true

Cases:
Curl Http://localhost:8983/solr/test/schema/fieldtypes?wt=json

-List Copy Fields

Path parameters:
/collection/

Request Parameters:
Wt=json/xml
Source.fl=
Dest.fl=

Cases:
Curl Http://localhost:8983/solr/test/schema/copyfields?wt=json

-Show Schema Name

Curl Http://localhost:8983/solr/test/schema/name?wt=json

-Show the Schema Version

Curl Http://localhost:8983/solr/test/schema/version?wt=json

-List UniqueKey

Curl Http://localhost:8983/solr/test/schema/uniquekey?wt=json

-Show Global Similarity

Curl Http://localhost:8983/solr/test/schema/similarity?wt=json

-Get the Default Query Operator

Curl Http://localhost:8983/solr/test/schema/solrqueryparser/defaultoperator?wt=json

1.4 Manage Resource Data

The Manage Resource REST API provides a mechanism for any SOLR plug-in to expose resources that support crud operations.






























Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.