Version Detection
solrpy automatically detects the Solr version at connection time and uses it to gate features at runtime.
How it works
When a Solr instance is created, _detect_version() is called during
initialization:
JSON API (Solr 4.0+):
GET /admin/info/system?wt=jsonXML fallback (Solr 3.x):
GET /admin/info/system?wt=xmlDefault:
(1, 2, 0)with a warning log if both attempts fail
Both the core path and its parent path are tried, so URLs like
http://host:8983/solr/core0 will also check /solr/admin/info/system.
Accessing the version
The detected version is stored as a tuple:
import solr
conn = solr.Solr('http://localhost:8983/solr/mycore')
print(conn.server_version) # e.g. (6, 6, 6)
major, minor, patch = conn.server_version
if major >= 9:
print('KNN search is available')
SolrVersionError
When a feature requires a Solr version higher than what is connected,
a SolrVersionError is raised:
import solr
conn = solr.Solr('http://localhost:8983/solr/mycore')
# if connected to Solr 3.x:
# solr.core.SolrVersionError: atomic_update requires Solr 4.0+,
# but connected to Solr 3.6.2
The exception has these attributes:
Attribute |
Description |
|---|---|
|
Name of the feature that was called |
|
Minimum version tuple required, e.g. |
|
Detected server version tuple, e.g. |
requires_version decorator
The requires_version decorator is used internally to guard methods:
from solr.core import requires_version
class Solr:
@requires_version(4, 0)
def atomic_update(self, doc):
...
If self.server_version is lower than the specified minimum, the decorator
raises SolrVersionError before the method body executes.
Supported Solr versions
solrpy targets all Solr versions from 1.2 through 10.x. The version detection mechanism ensures that features are only used when the connected Solr instance supports them.
Feature |
Minimum Solr |
|---|---|
Basic query and indexing |
1.2 |
Grouping ( |
3.3 |
Atomic Update ( |
4.0 |
Soft Commit ( |
4.0 |
Real-time Get ( |
4.0 |
MoreLikeThis ( |
4.0 |
Schema API ( |
4.2 |
Cursor Pagination ( |
4.7 |
JSON Facet API ( |
5.0 |
Dense Vector Search ( |
9.0 |
KNN |
10.0 |