1.4.7 Schema API

Schema API

  Schema API允许使用REST API每个集合(collection)(或者单机solr的核(core)).包含了定义字段类型,字段,动态字段,复制字段等.在solr4.2或4.3中,仅仅允许Get(只读)访问,在solr4.4上,新的字段和复制字段可以直接加入到schema中.未来,solr版本将会扩展这个功能,以允许更多的schema元素可以被更新.

  使用API启动schema修改,请参考Managed Schema Definition in SolrConfig.

  对于所有的调用,这个API支持两种模式:JSON和XML.当请求了完整的Schema之后,会有另外一种仿照schema.xml文件本身的XML模式.

  API的基本地址:http://<host>:<port>/<context-path>,其中<context-path>通常都是solr.

1.API入口点

  2.检索Schema信息

    2.1检索完成的schema

    2.2列出字段

    2.3列出指定的字段

    2.4列出动态字段

    2.5列出指定的动态字段规则

    2.6列出字段类型

    2.7列出指定的字段类型

    2.8列出复制字段

    2.9显示schema名字

    2.10显示schema版本

    2.11列出唯一主键Unique

    2.12显示全局Similarity

    2.13获取默认的查询操作

  3.修改schema

    3.1创建新的schema字段

    3.2创建一个新的schema字段

    3.3 直接创建新的复制字段

  4.相关主题

  1.API入口点 

    /collection/schema:检索整个schema.

/collection/schema/fields:检索所有定义的字段的信息,或者使用copyField直接常见新的字段.

/collection/schema/fields/name:检索一个字段的信息,或者使用copyField命令直接创建一个新的命名的字段.

/collection/schema/dynamicfields:检索动态字段规则信息

/collection/schema/dynamicfields/name:检索一个命名的动态字段信息

/collection/schema/fieldtypes:检索字段类型

/collection/schema/fieldtypes/name:检索一个命名的字段类型

/collection/schema/copyfields:检索复制字段或者创建新的复制字段

/collection/schema/name:取回schema的名称

/collection/schema/version:取回schema的版本

/collection/schema/uniquekey:取回定义的uniquekey

/collection/schema/similarity:取回全局的similarity

/collection/schema/solrqueryparser/defaultoperator:检索默认操作

  2.检索Schema信息

    2.1检索完成的schema

      GET  /collection/schema

      输入

      路径参数

        collection:collection或者core的名称

      查询参数

        查询参数可以放在API请求的问号"?"之后.

Key Type Required Default Description
wt string No json

定义响应格式,选项可以是json,xml或者是schema.xml.

如果没有指定,JSON将会被默认返回

     输出

        输出内容将包含所有的字段,字段类型,动态字段,复制字段.同样也包含schema名称和版本号.

      例子

        输入

        采用json方式取回全部的schema

curl http://localhost:8983/solr/collection1/schema?wt=json

        采用xml方式取回全部的schema

curl http://localhost:8983/solr/collection1/schema?wt=xml

         采用 "schema.xml"方式取回全部的schema    

curl http://localhost:8983/solr/collection1/schema?wt=schema.xml

        输出

        JSON例子:      

{
"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},
...
"copyFields":[{
"source":"author",
"dest":"text"},
{
"source":"cat",
"dest":"text"},
{
"source":"content",
"dest":"text"},
...
{
"source":"author",
"dest":"author_s"}]}}
View Code

        XML例子: 

<?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>
View Code

        schema.xml格式例子

<?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>
View Code

    2.2列出字段

      GET  /collection/schema/fields

     输入

      路径参数

        collection:collection或者core的名称

      查询参数

Key Type Required Default Description
wt string No json

定义响应格式,选项可以是json,xml或者是schema.xml.

如果没有指定,JSON将会被默认返回

       输出

      取回所有字段的列表

curl http://localhost:8983/solr/collection1/schema/fields?wt=json

          结果

{
"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"
},
...
],
"responseHeader": {
"QTime": 1,
"status": 0
}
}
View Code

      2.3列出指定的字段

      GET /collection/schema/fields/fieldname

      输入

        路径参数:

          collection:集合或核的名称

          filedname:指定字段名称

        查询参数:

         查询参数可以加入到request请求问号?之后.

Key Type Required Default Description
wt string No json

定义响应格式,选项可以是json,xml或者是schema.xml.

如果没有指定,JSON将会被默认返回

 

    2.4列出动态字段

    2.5列出指定的动态字段规则

    2.6列出字段类型

    2.7列出指定的字段类型

    2.8列出复制字段

    2.9显示schema名字

    2.10显示schema版本

    2.11列出唯一主键Unique

    2.12显示全局Similarity

    2.13获取默认的查询操作

  3.修改schema

    3.1创建新的schema字段

    3.2创建一个新的schema字段

    3.3 直接创建新的复制字段

  4.相关主题

  

原文地址:https://www.cnblogs.com/a198720/p/4287100.html