Skip to content

xue-ding-e/manticoresearch-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Manticorer Go client

Сlient for Manticore Search.

❗ WARNING: this is a development version of the client. The latest release's readme is https://github.com/manticoresoftware/manticoresearch-go/tree/v1.0.0

Requiments

Manticore Search manticoresearch-go Go
dev dev >= 1.17.0
>= 6.2.12 v1.0.0 >= 1.17.0

Installation

go get github.com/manticoresoftware/manticoresearch-go@dev 

Getting Started

package main

import (
	"context"
	"fmt"
	"os"
	"strings"
	openapiclient "github.com/manticoresoftware/manticoresearch-go"
)

func main() {
  
  // Initialize ApiClient
  openapiclient.SetDefaultIP("127.0.0.1") // If not set or set to "", defaults to 127.0.0.1
  configuration := openapiclient.NewConfiguration()
  // Set Manticore's host/port if necessary (http://127.0.0.1:9308 by default) 
  // configuration.Servers[0].URL = "http://127.0.0.2:9408"
  apiClient := openapiclient.NewAPIClient(configuration)
  
  // Add documents to an index 
  docs := []string {
	"{\"insert\": {\"index\" : \"test\", \"id\" : 1, \"doc\" : {\"title\" : \"Title 1\"}}}",
	"{\"insert\": {\"index\" : \"test\", \"id\" : 2, \"doc\" : {\"title\" : \"Title 2\"}}}",
  }
  apiClient.IndexAPI.Bulk(context.Background()).Body(strings.Join(docs[:], "\n")).Execute()
  
  // response from `Search`: SearchRequest
  searchRequest := *openapiclient.NewSearchRequest("test")
  
  // Perform a search
  query := map[string]interface{} {"query_string": "Title"}
  searchRequest.SetQuery(query)
  resp, r, err := apiClient.SearchAPI.Search(context.Background()).SearchRequest(searchRequest).Execute()
  
  if err != nil {
	fmt.Fprintf(os.Stderr, "Error when calling `SearchAPI.Search``: %v\n", err)
	fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
  }
  // response from `Search`: SearchResponse
  fmt.Fprintf(os.Stdout, "Response from `SearchAPI.Search`: %v\n", resp)
}

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value openapi.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value openapi.ContextServerVariables of type map[string]string.

For example, if your Manticore server is available through the '/manticore' path, you should set basePath appropriately. This will rewrite all your requests: e.g., '/search' to '/manticore/search', etc.

ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
	"basePath": "manticore",
})

Note, enum values are always validated and all unused variables are silently ignored.

Using proxy

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

More details on the use of HTTP_PROXY can be found here

Documentation for API Endpoints

All URIs are relative to http://127.0.0.1:9308

Class Method HTTP request Description
IndexAPI Bulk Post /bulk Bulk index operations
IndexAPI Delete Post /delete Delete a document in an index
IndexAPI Insert Post /insert Create a new document in an index
IndexAPI Replace Post /replace Replace new document in an index
IndexAPI Update Post /update Update a document in an index
IndexAPI Update_0 Post /{index}/_update/{id} Partially replaces a document in an index
SearchAPI Percolate Post /pq/{index}/search Perform reverse search on a percolate index
SearchAPI Search Post /search Performs a search on an index
UtilsAPI Sql Post /sql Perform SQL requests

Documentation For Models

Documentation For Authorization

Endpoints do not require authorization.

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

About

Official Go client for Manticore Search

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 91.0%
  • Go 9.0%