Documentation ¶
Overview ¶
Package goes provides an API to access Elasticsearch.
Index ¶
- Constants
- type All
- type Connection
- func (c *Connection) BulkSend(index string, documents []Document) (Response, error)
- func (c *Connection) CreateIndex(name string, mapping map[string]interface{}) (Response, error)
- func (c *Connection) Delete(d Document, extraArgs url.Values) (Response, error)
- func (c *Connection) DeleteIndex(name string) (Response, error)
- func (c *Connection) Get(index string, documentType string, id string, extraArgs url.Values) (Response, error)
- func (c *Connection) Index(d Document, extraArgs url.Values) (Response, error)
- func (c *Connection) IndexStatus(indexList []string) (Response, error)
- func (c *Connection) RefreshIndex(name string) (Response, error)
- func (c *Connection) Scan(query interface{}, indexList []string, typeList []string, timeout string, ...) (Response, error)
- func (c *Connection) Scroll(scrollId string, timeout string) (Response, error)
- func (c *Connection) Search(query interface{}, indexList []string, typeList []string) (Response, error)
- func (c *Connection) Stats(indexList []string, extraArgs url.Values) (Response, error)
- type Document
- type Hit
- type Hits
- type IndexStatus
- type Item
- type Request
- type Response
- type SearchError
- type Shard
- type StatIndex
- type StatPrimary
Examples ¶
Constants ¶
const ( BULK_COMMAND_INDEX = "index" BULK_COMMAND_DELETE = "delete" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type All ¶
type All struct { Indices map[string]StatIndex `json:"indices"` Primaries map[string]StatPrimary `json:"primaries"` }
Represents the "_all" field when calling the _stats API This is minimal but this is what I only need
type Connection ¶
Represents a Connection object to elasticsearch
func NewConnection ¶
func NewConnection(host string, port int) *Connection
NewConnection initiates a new Connection to an elasticsearch server
This function is pretty useless for now but might be useful in a near future if wee need more features like connection pooling or load balancing.
func (*Connection) BulkSend ¶
func (c *Connection) BulkSend(index string, documents []Document) (Response, error)
Bulk adds multiple documents in bulk mode to the index for a given type
func (*Connection) CreateIndex ¶
func (c *Connection) CreateIndex(name string, mapping map[string]interface{}) (Response, error)
CreateIndex creates a new index represented by a name and a mapping
Example ¶
package main import ( "fmt" "github.com/belogik/goes" ) func main() { conn := goes.NewConnection("localhost", 9200) mapping := map[string]interface{}{ "settings": map[string]interface{}{ "index.number_of_shards": 1, "index.number_of_replicas": 0, }, "mappings": map[string]interface{}{ "_default_": map[string]interface{}{ "_source": map[string]interface{}{ "enabled": true, }, "_all": map[string]interface{}{ "enabled": false, }, }, }, } resp, err := conn.CreateIndex("test", mapping) if err != nil { panic(err) } fmt.Printf("%s", resp) }
Output:
func (*Connection) Delete ¶
Delete deletes a Document d The extraArgs is a list of url.Values that you can send to elasticsearch as URL arguments, for example, to control routing.
Example ¶
package main import ( "fmt" "github.com/belogik/goes" "net/url" ) func main() { conn := goes.NewConnection("localhost", 9200) //[create index, index document ...] d := goes.Document{ Index: "twitter", Type: "tweet", Id: "1", Fields: map[string]interface{}{ "user": "foo", }, } response, err := conn.Delete(d, url.Values{}) if err != nil { panic(err) } fmt.Printf("%s", response) }
Output:
func (*Connection) DeleteIndex ¶
func (c *Connection) DeleteIndex(name string) (Response, error)
DeleteIndex deletes an index represented by a name
Example ¶
package main import ( "fmt" "github.com/belogik/goes" ) func main() { conn := goes.NewConnection("localhost", 9200) resp, err := conn.DeleteIndex("yourinde") if err != nil { panic(err) } fmt.Printf("%s", resp) }
Output:
func (*Connection) Get ¶
func (c *Connection) Get(index string, documentType string, id string, extraArgs url.Values) (Response, error)
Get a typed document by its id
func (*Connection) Index ¶
Index indexes a Document The extraArgs is a list of url.Values that you can send to elasticsearch as URL arguments, for example, to control routing, ttl, version, op_type, etc.
Example ¶
package main import ( "fmt" "github.com/belogik/goes" "net/url" ) func main() { conn := goes.NewConnection("localhost", 9200) d := goes.Document{ Index: "twitter", Type: "tweet", Fields: map[string]interface{}{ "user": "foo", "message": "bar", }, } extraArgs := make(url.Values, 1) extraArgs.Set("ttl", "86400000") response, err := conn.Index(d, extraArgs) if err != nil { panic(err) } fmt.Printf("%s", response) }
Output:
func (*Connection) IndexStatus ¶
func (c *Connection) IndexStatus(indexList []string) (Response, error)
IndexStatus fetches the status (_status) for the indices defined in indexList. Use _all in indexList to get stats for all indices
func (*Connection) RefreshIndex ¶
func (c *Connection) RefreshIndex(name string) (Response, error)
RefreshIndex refreshes an index represented by a name
Example ¶
package main import ( "fmt" "github.com/belogik/goes" ) func main() { conn := goes.NewConnection("localhost", 9200) resp, err := conn.RefreshIndex("yourindex") if err != nil { panic(err) } fmt.Printf("%s", resp) }
Output:
func (*Connection) Scan ¶
func (c *Connection) Scan(query interface{}, indexList []string, typeList []string, timeout string, size int) (Response, error)
Scan starts scroll over an index
func (*Connection) Scroll ¶
func (c *Connection) Scroll(scrollId string, timeout string) (Response, error)
Scroll fetches data by scroll id
func (*Connection) Search ¶
func (c *Connection) Search(query interface{}, indexList []string, typeList []string) (Response, error)
Search executes a search query against an index
Example ¶
package main import ( "fmt" "github.com/belogik/goes" ) func main() { conn := goes.NewConnection("localhost", 9200) var query = map[string]interface{}{ "query": map[string]interface{}{ "bool": map[string]interface{}{ "must": map[string]interface{}{ "match_all": map[string]interface{}{}, }, }, }, "from": 0, "size": 100, "fields": []string{"onefield"}, "filter": map[string]interface{}{ "range": map[string]interface{}{ "somefield": map[string]interface{}{ "from": "some date", "to": "some date", "include_lower": false, "include_upper": false, }, }, }, } searchResults, err := conn.Search(query, []string{"someindex"}, []string{""}) if err != nil { panic(err) } fmt.Printf("%s", searchResults) }
Output:
type Document ¶
type Document struct { // XXX : interface as we can support nil values Index interface{} Type string Id interface{} BulkCommand string Fields interface{} Parent interface{} }
Represents a document to send to elasticsearch
type Hit ¶
type Hit struct { Index string `json:"_index"` Type string `json:"_type"` Id string `json:"_id"` Score float64 `json:"_score"` Source json.RawMessage `json:"_source"` Fields json.RawMessage `json:"fields"` }
Represent a hit returned by a search
type Hits ¶
type Hits struct { Total uint64 // max_score may contain the "null" value MaxScore interface{} `json:"max_score"` Hits []Hit }
Represent the hits structure as returned by elasticsearch
type IndexStatus ¶
type IndexStatus struct { // XXX : problem, int will be marshaled to a float64 which seems logical // XXX : is it better to use strings even for int values or to keep // XXX : interfaces and deal with float64 ? Index map[string]interface{} Translog map[string]uint64 Docs map[string]uint64 Merges map[string]interface{} Refresh map[string]interface{} Flush map[string]interface{} }
Represent the status for a given index for the _status command
type Item ¶
type Item struct { Ok bool `json:"ok"` Type string `json:"_type"` Id string `json:"_id"` Index string `json:"_index"` Version int `json:"_version"` }
Represents the "items" field in a _bulk response
type Request ¶
type Request struct { // Which connection will be used Conn *Connection // A search query Query interface{} // Which index to search into IndexList []string // Which type to search into TypeList []string // Request body Body []byte // A list of extra URL arguments ExtraArgs url.Values // contains filtered or unexported fields }
Represents a Request to elasticsearch
type Response ¶
type Response struct { Ok bool Acknowledged bool Error string Errors bool `json:"errors"` Status uint64 Took uint64 TimedOut bool `json:"timed_out"` Shards Shard `json:"_shards"` Hits Hits Index string `json:"_index"` Id string `json:"_id"` Type string `json:"_type"` Version int `json:"_version"` Found bool // Used by the _stats API All All `json:"_all"` // Used by the _bulk API Items json.RawMessage `json:"items,omitempty"` // Used by the GET API Exists bool Source json.RawMessage `json:"_source"` Fields json.RawMessage `json:"fields"` // Used by the _status API Indices map[string]IndexStatus // Scroll id for iteration ScrollId string `json:"_scroll_id"` }
Represents a Response from elasticsearch
type SearchError ¶
func (*SearchError) Error ¶
func (err *SearchError) Error() string
type StatIndex ¶
type StatIndex struct {
Primaries map[string]StatPrimary `json:"primaries"`
}