Does solr has API to read solr schema.xml?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:21:58

问题


Is there any solr api to read the solr schema.xml? The reason I need it is that solr facet is not backward compatible. If the index doesn't define field A, but the program tries to generate facet for field A, all the facets will fail.Therefore I need to check in the runtime what index fields do we have in the index and generate the facets dynamically.


回答1:


You can get the schema with http://localhost:8983/solr/admin/file/?contentType=text/xml;charset=utf-8&file=schema.xml

It's the raw xml, so have to parse it to get the information you need.

However, if your program generates an invalid facet, maybe you should just fix the program instead of trying to work around this.




回答2:


One alternative is to use LukeRequestHandler. It is modeled after Luke tool which is used to diagnose the content of Lucene Index. The query /admin/luke?show=schema, will show you the schema. However, you will need to define it in solrconfig.xml like so :

<requestHandler name="/admin/luke" class="org.apache.solr.handler.admin.LukeRequestHandler" />

Documentation of LukeRequestHandler link




回答3:


Since Solr 4.2 the Schema REST API allows you to get the schema with :

http://localhost:8983/solr/schema

or with a core name :

http://localhost:8983/solr/mycorename/schema

Since Solr 4.4 you may also modify your schema.

more details on the Solr Wiki page




回答4:


Actually you have the Schema API for that. The Solr schema API allows using a REST API to get information about the schema.xml

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

API Entry Points

/collection/schema: retrieve the entire schema
/collection/schema/fields: retrieve information about all defined fields, or create new     fields with optional copyField directives
/collection/schema/fields/name: retrieve information about a named field, or create a new named field with optional copyField directives
/collection/schema/dynamicfields: retrieve information about dynamic field rules
/collection/schema/dynamicfields/name: retrieve information about a named dynamic rule
/collection/schema/fieldtypes: retrieve information about field types
/collection/schema/fieldtypes/name: retrieve information about a named field type
/collection/schema/copyfields: retrieve information about copy fields, or create new copyField directives
/collection/schema/name: retrieve the schema name
/collection/schema/version: retrieve the schema version
/collection/schema/uniquekey: retrieve the defined uniqueKey
/collection/schema/similarity: retrieve the global similarity definition
/collection/schema/solrqueryparser/defaultoperator: retrieve the default operator

Examples

Input Get a list of all fields.

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

Input Get the entire schema in JSON.

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

More info here: apache-solr-ref-guide-4.5.pdf (search for Schema API)



来源:https://stackoverflow.com/questions/7247221/does-solr-has-api-to-read-solr-schema-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!