检索模式信息

以下终端允许你读取模式如何定义的信息。你可以 GET 整个模式或需要的部分。

要修改模式,查看前一小节 修改模式

检索整个模式

  1. GET /collection/schema

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将根据请求格式(JSON 或 xml),包含所有字段、字段类型、动态规则和拷贝字段规则。 模式名称和版本也会被包含。

示例

以 JSON 获取整个模式

  1. curl http://localhost:8983/solr/gettingstarted/schema?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":5},
  5. "schema":{
  6. "name":"example",
  7. "version":1.5,
  8. "uniqueKey":"id",
  9. "fieldTypes":[{
  10. "name":"alphaOnlySort",
  11. "class":"solr.TextField",
  12. "sortMissingLast":true,
  13. "omitNorms":true,
  14. "analyzer":{
  15. "tokenizer":{
  16. "class":"solr.KeywordTokenizerFactory"},
  17. "filters":[{
  18. "class":"solr.LowerCaseFilterFactory"},
  19. {
  20. "class":"solr.TrimFilterFactory"},
  21. {
  22. "class":"solr.PatternReplaceFilterFactory",
  23. "replace":"all",
  24. "replacement":"",
  25. "pattern":"([^a-z])"}]}},
  26. ...
  27. "fields":[{
  28. "name":"_version_",
  29. "type":"long",
  30. "indexed":true,
  31. "stored":true},
  32. {
  33. "name":"author",
  34. "type":"text_general",
  35. "indexed":true,
  36. "stored":true},
  37. {
  38. "name":"cat",
  39. "type":"string",
  40. "multiValued":true,
  41. "indexed":true,
  42. "stored":true},
  43. ...
  44. "copyFields":[{
  45. "source":"author",
  46. "dest":"text"},
  47. {
  48. "source":"cat",
  49. "dest":"text"},
  50. {
  51. "source":"content",
  52. "dest":"text"},
  53. ...
  54. {
  55. "source":"author",
  56. "dest":"author_s"}]}}

以 XML 格式获取整个模式

  1. curl http://localhost:8983/solr/gettingstarted/schema?wt=xml
  1. <response>
  2. <lst name="responseHeader">
  3. <int name="status">0</int>
  4. <int name="QTime">5</int>
  5. </lst>
  6. <lst name="schema">
  7. <str name="name">example</str>
  8. <float name="version">1.5</float>
  9. <str name="uniqueKey">id</str>
  10. <arr name="fieldTypes">
  11. <lst>
  12. <str name="name">alphaOnlySort</str>
  13. <str name="class">solr.TextField</str>
  14. <bool name="sortMissingLast">true</bool>
  15. <bool name="omitNorms">true</bool>
  16. <lst name="analyzer">
  17. <lst name="tokenizer">
  18. <str name="class">solr.KeywordTokenizerFactory</str>
  19. </lst>
  20. <arr name="filters">
  21. <lst>
  22. <str name="class">solr.LowerCaseFilterFactory</str>
  23. </lst>
  24. <lst>
  25. <str name="class">solr.TrimFilterFactory</str>
  26. </lst>
  27. <lst>
  28. <str name="class">solr.PatternReplaceFilterFactory</str>
  29. <str name="replace">all</str>
  30. <str name="replacement"/>
  31. <str name="pattern">([^a-z])</str>
  32. </lst>
  33. </arr>
  34. </lst>
  35. </lst>
  36. ...
  37. <lst>
  38. <str name="source">author</str>
  39. <str name="dest">author_s</str>
  40. </lst>
  41. </arr>
  42. </lst>
  43. </response>

以 “schema.xml” 格式获取整个模式

  1. curl http://localhost:8983/solr/gettingstarted/schema?wt=schema.xml
  1. <schema name="example" version="1.5">
  2. <uniqueKey>id</uniqueKey>
  3. <types>
  4. <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true"
  5. omitNorms="true">
  6. <analyzer>
  7. <tokenizer class="solr.KeywordTokenizerFactory"/>
  8. <filter class="solr.LowerCaseFilterFactory"/>
  9. <filter class="solr.TrimFilterFactory"/>
  10. <filter class="solr.PatternReplaceFilterFactory" replace="all"
  11. replacement="" pattern="([^a-z])"/>
  12. </analyzer>
  13. </fieldType>
  14. ...
  15. <copyField source="url" dest="text"/>
  16. <copyField source="price" dest="price_c"/>
  17. <copyField source="author" dest="author_s"/>
  18. </schema>

列出字段

  1. GET /collection/schema/fields
  2. GET /collection/schema/fields/fieldname

输入

路径变量

描述
collection 集合(或 core)的名称
fieldname 特定字段名称(若限制仅请求单个字段)

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含每个字段和针对每个字段的任何定义的配置。 对每个字段的定义的配置可能有差别,但至少会包含字段 name 及其 type、其是否 indexed 及是否 stored。 若 multiValued 被定义为 true 或 false (通常为 true),它也将显示。 查看 定义字段 中每个参数的更多信息。

示例

获取所有字段的列表

  1. curl http://localhost:8983/solr/gettingstarted/schema/fields?wt=json

以下示例输出被截取仅显示其中一部分

  1. {
  2. "fields": [
  3. {
  4. "indexed": true,
  5. "name": "_version_",
  6. "stored": true,
  7. "type": "long"
  8. },
  9. {
  10. "indexed": true,
  11. "name": "author",
  12. "stored": true,
  13. "type": "text_general"
  14. },
  15. {
  16. "indexed": true,
  17. "multiValued": true,
  18. "name": "cat",
  19. "stored": true,
  20. "type": "string"
  21. },
  22. ...
  23. ],
  24. "responseHeader": {
  25. "QTime": 1,
  26. "status": 0
  27. }
  28. }

列出动态字段

  1. GET /collection/schema/dynamicfields
  2. GET /collection/schema/dynamicfields/name

输入

路径变量

描述
collection 集合(或 core)的名称
name 动态字段规则名称(若限制仅请求单个动态字段规则)

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含每个动态字段规则和针对每个动态字段规则的任何定义的配置。 对每个动态字段规则的定义的配置可能有差别,但至少会包含字段 name 及其 type、其是否 indexed 及是否 stored。 查看 动态字段 中每个参数的更多信息。

示例

获取所有动态字段声明的列表:

  1. curl http://localhost:8983/solr/gettingstarted/schema/dynamicfields?wt=json

以下是被截取的示例输出:

  1. {
  2. "dynamicFields": [
  3. {
  4. "indexed": true,
  5. "name": "*_coordinate",
  6. "stored": false,
  7. "type": "tdouble"
  8. },
  9. {
  10. "multiValued": true,
  11. "name": "ignored_*",
  12. "type": "ignored"
  13. },
  14. {
  15. "name": "random_*",
  16. "type": "random"
  17. },
  18. {
  19. "indexed": true,
  20. "multiValued": true,
  21. "name": "attr_*",
  22. "stored": true,
  23. "type": "text_general"
  24. },
  25. {
  26. "indexed": true,
  27. "multiValued": true,
  28. "name": "*_txt",
  29. "stored": true,
  30. "type": "text_general"
  31. }
  32. ...
  33. ],
  34. "responseHeader": {
  35. "QTime": 1,
  36. "status": 0
  37. }
  38. }

列出字段类型

  1. GET /collection/schema/fieldtypes
  2. GET /collection/schema/fieldtypes/name

输入

路径变量

描述
collection 集合(或 core)的名称
name 字段类型名称(若限制仅请求单个字段类型)

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含每个字段类型和针对每个字段类型的任何定义的配置。 对每个字段类型的定义的配置可能有差别,但至少会包含字段 name 及其 class。 若定义了查询或索引分析器、分词器或过滤器,它们将和其它定义的参数一起显示。 查看 Solr 字段类型 中关于如何配置多种字段类型的更多信息。

示例

获取所有字段类型的列表

  1. curl http://localhost:8983/solr/gettingstarted/schema/fieldtypes?wt=json

以下被截取的示例输出显示了列表中不同部分的一些不同的字段类型。

  1. {
  2. "fieldTypes": [
  3. {
  4. "analyzer": {
  5. "class": "solr.TokenizerChain",
  6. "filters": [
  7. {
  8. "class": "solr.LowerCaseFilterFactory"
  9. },
  10. {
  11. "class": "solr.TrimFilterFactory"
  12. },
  13. {
  14. "class": "solr.PatternReplaceFilterFactory",
  15. "pattern": "([^a-z])",
  16. "replace": "all",
  17. "replacement": ""
  18. }
  19. ],
  20. "tokenizer": {
  21. "class": "solr.KeywordTokenizerFactory"
  22. }
  23. },
  24. "class": "solr.TextField",
  25. "dynamicFields": [],
  26. "fields": [],
  27. "name": "alphaOnlySort",
  28. "omitNorms": true,
  29. "sortMissingLast": true
  30. },
  31. ...
  32. {
  33. "class": "solr.TrieFloatField",
  34. "dynamicFields": [
  35. "*_fs",
  36. "*_f"
  37. ],
  38. "fields": [
  39. "price",
  40. "weight"
  41. ],
  42. "name": "float",
  43. "positionIncrementGap": "0",
  44. "precisionStep": "0"
  45. },
  46. ...
  47. }

列出拷贝字段

  1. GET /collection/schema/copyfields

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含定义在 schema.xml 中每个拷贝字段规则的 sourcedest。 更多有关拷贝字段的信息,查看 拷贝字段

示例

获取所有拷贝字段的列表

  1. curl http://localhost:8983/solr/gettingstarted/schema/copyfields?wt=json

以下示例输出被截取仅显示部分拷贝定义

  1. {
  2. "copyFields": [
  3. {
  4. "dest": "text",
  5. "source": "author"
  6. },
  7. {
  8. "dest": "text",
  9. "source": "cat"
  10. },
  11. {
  12. "dest": "text",
  13. "source": "content"
  14. },
  15. {
  16. "dest": "text",
  17. "source": "content_type"
  18. },
  19. ...
  20. ],
  21. "responseHeader": {
  22. "QTime": 3,
  23. "status": 0
  24. }
  25. }

显示模式名称

  1. GET /collection/schema/name

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将简单地显示模式的名称

示例

获取模式名称

  1. curl http://localhost:8983/solr/gettingstarted/schema/name?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":1},
  5. "name":"example"}

显示模式版本

  1. GET /collection/schema/version

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将简单地显示使用的模式的版本号

示例

获取模式版本

  1. curl http://localhost:8983/solr/gettingstarted/schema/version?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":2},
  5. "version":1.5}

列出唯一键

  1. GET /collection/schema/uniquekey

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中仅简单包含用作索引唯一键的字段的名称

示例

列出唯一键

  1. curl http://localhost:8983/solr/gettingstarted/schema/uniquekey?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":2},
  5. "uniqueKey":"id"}

显示全局相似度

  1. GET /collection/schema/similarity

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含全局定义的相似度(如果存在的话)的类的名称

示例

获取相似度实现

  1. curl http://localhost:8983/solr/gettingstarted/schema/similarity?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":1},
  5. "similarity":{
  6. "class":"org.apache.solr.search.similarities.DefaultSimilarityFactory"}}

获取默认查询操作符

  1. GET /collection/schema/solrqueryparser/defaultoperator

输入

路径变量

描述
collection 集合(或 core)的名称

查询参数

查询参数应该在 API 请求的 ‘?’ 后添加

类型 必需 默认 描述
wt string No json 定义响应格式。可选项有 jsonxmlschema.xml。若没有指定,将默认返回 JSON。

输出

输出内容

输出中将包含用户没有定义时的默认操作符。

示例

获取默认操作符

  1. curl http://localhost:8983/solr/gettingstarted/schema/solrqueryparser/defaultoperator?wt=json
  1. {
  2. "responseHeader":{
  3. "status":0,
  4. "QTime":2},
  5. "defaultOperator":"OR"}