项目作者: adrianolaselva

项目描述 :
Apache Solr client for GO
高级语言: Go
项目地址: git://github.com/adrianolaselva/solr-client-go.git
创建时间: 2020-04-30T11:25:39Z
项目社区:https://github.com/adrianolaselva/solr-client-go

开源协议:Apache License 2.0

下载


Build Status
Scrutinizer Code Quality
GoDoc
license

Apache Solr client Go

This is a Go client library to access Apache Solr APIs to enable the use of operations from document manipulation to index management.

Install

  1. go get github.com/adrianolaselva/solr-client-go/solr

Usage

  1. import "github.com/adrianolaselva/solr-client-go/solr"

Create a new Solr customer to consume the endpoints.

Examples

Instantiate solr client:

  1. client := solr.NewClient()

Find Documents:

  1. response, err := client.Document.Select(context.Background(), "identify-events", "*:*")
  2. if err != nil {
  3. log.Info(err)
  4. }

Create Document(s):

  1. var docs []solr.Document
  2. docs = append(docs, map[string]interface{}{
  3. "uuid": fmt.Sprintf("%x", md5.Sum([]byte(time.Now().String()))),
  4. "context": map[string]interface{}{
  5. "ip": "127.0.0.1",
  6. },
  7. "timestamp": "2020-04-27 16:43:57-0300",
  8. })
  9. response, err := client.Document.Update(context.Background(), "identify-events", docs, &solr.Parameters{
  10. Commit: true,
  11. })

Delete by ID:

  1. d := Delete{
  2. Id: id,
  3. }
  4. response, err = client.Document.Delete(context.Background(), "identify-events", d, &Parameters{
  5. Commit: true,
  6. })

Delete by Query:

  1. d := Delete{
  2. Query: "context.ip: 127.0.0.1",
  3. }
  4. response, err = client.Document.Delete(context.Background(), "identify-events", d, &Parameters{
  5. Commit: true,
  6. })

Create new collection:

  1. response, err := client.Collection.Create(context.Background(), CollectionCreate{
  2. Name: "collection-test",
  3. RouterName: "compositeId",
  4. NumShards: 1,
  5. ReplicationFactor: 1,
  6. CollectionConfigName: "_default",
  7. Async: false,
  8. })

Reload Collection:

  1. response, err := client.Collection.Reload(context.Background(), CollectionReload{
  2. Name: "collection-test",
  3. Async: false,
  4. })

Modify Collection:

  1. response, err := client.Collection.Modify(context.Background(), CollectionModifyCollection{
  2. Collection: "collection-test",
  3. MaxShardsPerNode: 1,
  4. })

List Collections:

  1. response, err := client.Collection.List(context.Background())

Migrate collection

  1. response, err = client.Collection.Migrate(context.Background(), CollectionMigrate{
  2. Collection: "collection-test",
  3. TargetCollection: "collection-test-migrate",
  4. SplitKey: "a!",
  5. ForwardTimeout: 100000,
  6. Async: false,
  7. })

Collection backup:

  1. response, err := client.Collection.Backup(context.Background(), CollectionBackup{
  2. Collection: "collection-test",
  3. Name: backupFilePath,
  4. Location: "/tmp/",
  5. Async: false,
  6. })

Collection restore:

  1. response, err = client.Collection.Restore(context.Background(), CollectionRestore{
  2. Collection: backupFilePath,
  3. Name: backupFilePath,
  4. Location: "/tmp/",
  5. Async: false,
  6. ReplicationFactor: 1,
  7. })

Create collection configuration:

  1. response, err := client.Config.Upload(context.Background(), "../example/configs/identify-events.zip", "identify-events")

Obs: example collection settings in the ./example/configs/ directory.

Create a new configuration using another as a base:

  1. response, err := client.Config.Create(context.Background(), CreateConfig{
  2. Create: Config{
  3. Name: "identify-events.CREATE",
  4. BaseConfigSet: "identify-events",
  5. },
  6. })

Remove collection configuration:

  1. response, err := client.Config.Delete(context.Background(), "identify-events")

Atomic Updates:

  1. var docs []Document
  2. docs = append(docs, map[string]interface{}{
  3. "id": id,
  4. "author_s": map[string]interface{}{
  5. "set": "Teste 2",
  6. },
  7. "copies_i": map[string]interface{}{
  8. "inc": 5,
  9. },
  10. "cat_ss": map[string]interface{}{
  11. "add": time.Now().Format(time.RFC3339),
  12. },
  13. })
  14. response, err = client.Document.AtomicUpdateMany(context.Background(), "identify-events", docs, &Parameters{
  15. Commit: true,
  16. })

Obs: Solr supports several modifiers that atomically update values of a document. This allows updating only specific fields, which can help speed indexing processes in an environment where speed of index additions is critical to the application.

To use atomic updates, add a modifier to the field that needs to be updated. The content can be updated, added to, or incrementally increased if a number.

Atomic update

Versioning

Each version of the client is tagged and the version is updated accordingly.

To see the list of past versions, run git tag.

License

MIT