https://github.com/mecenat/solr
A Solr client written in Go
https://github.com/mecenat/solr
core-api go-solr golang schema-api solr solr-client solr-core-api solr-query solr-schema-api solr-search
Last synced: 2 months ago
JSON representation
A Solr client written in Go
- Host: GitHub
- URL: https://github.com/mecenat/solr
- Owner: mecenat
- License: other
- Created: 2020-06-16T14:12:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-29T11:51:40.000Z (8 months ago)
- Last Synced: 2026-01-14T13:56:24.556Z (4 months ago)
- Topics: core-api, go-solr, golang, schema-api, solr, solr-client, solr-core-api, solr-query, solr-schema-api, solr-search
- Language: Go
- Homepage:
- Size: 94.7 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# solr
A Solr client written in Go
Designed for Solr 8.5 (Should support earlier versions as well)
Provides clients for Solr's Request API, Schema API & Core Admin API
Currently supports only JSON and basic CRUDL actions.
## Installation
```
go get -u github.com/mecenat/solr
```
## Usage
To create a new solr Client you need first to create a Connection. To create a Connection you need the host location (e.g. http://localhost:8983), the core name, and a http client. Use `solr.NewDefaultHTTPClient()` for a client with sensible connection pooling defaults. Sending your own client could be useful when you need to wrap the client with another service, for example if you want to use AWS's X-Ray service to trace your API's calls or granular control over connection limits.
When using a single server:
```
package main
import "github.com/mecenat/solr"
func main() {
conn, err := solr.NewConnection("host", "core", solr.NewDefaultHTTPClient())
if err != nil {
...
}
slr, err := solr.NewSingleClient(conn)
if err != nil {
...
}
```
When using a the Primary-Replica paradigm:
```
package main
import "github.com/mecenat/solr"
func main() {
primaryConn, err := solr.NewConnection("primaryHost", "core", solr.NewDefaultHTTPClient())
if err != nil {
...
}
replicaConn, err := solr.NewConnection("replicaHost", "core", solr.NewDefaultHTTPClient())
if err != nil {
...
}
slr, err := solr.NewPrimaryReplicaClient(primaryConn, replicaConn)
if err != nil {
...
}
```
Aside from the normal Connection you can you a RetryableConnection which implements [Hashicorp's retryable HttpClient](https://github.com/hashicorp/go-retryablehttp) specifying the max timeout and provide that connection to the clients.
```
package main
import "github.com/mecenat/solr"
func main() {
retConn, err := solr.NewRetryableConnection("host", "core", solr.NewDefaultHTTPClient(), 500*time.Millisecond)
if err != nil {
...
}
slr, err := solr.NewSingleClient(retConn)
if err != nil {
...
}
```
To access Solr's Core Admin API you need to create a separate client as follows:
```
package main
import "github.com/mecenat/solr"
func main() {
ctx := context.Background()
ca, err := solr.NewCoreAdmin(ctx, "host", solr.NewDefaultHTTPClient())
if err != nil {
...
}
```
To access Solr's Schema API you also need a separate client as follows:
```
package main
import "github.com/mecenat/solr"
func main() {
ctx := context.Background()
sa, err := solr.NewSchemaAPI(ctx, "host", "core", solr.NewDefaultHTTPClient())
if err != nil {
...
}
```
## Releasing
To create a new release, push a semver tag to `master`:
```
git tag v1.5.0
git push origin v1.5.0
```
This triggers a GitHub Actions workflow that runs tests and creates a GitHub release with auto-generated notes.
## License
This library is licensed under the MIT license. It depends on github.com/hashicorp/go-cleanhttp and github.com/hashicorp/go-retryablehttp, which is licensed under the Mozilla Public License (MPL).