elastigo

package
v0.0.0-...-e1c5934 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2015 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2013 Matthew Baird Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2013 Matthew Baird Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Examples

Constants

View Source
const (
	Version         = "0.0.2"
	DefaultProtocol = "http"
	DefaultDomain   = "localhost"
	DefaultPort     = "9200"
	// A decay duration of zero results in the default behaviour
	DefaultDecayDuration = 0
)
View Source
const (
	// Max buffer size in bytes before flushing to elasticsearch
	BulkMaxBuffer = 16384
	// Max number of Docs to hold in buffer before forcing flush
	BulkMaxDocs = 100
	// Max delay before forcing a flush to Elasticearch
	BulkDelaySeconds = 5
	// maximum wait shutdown seconds
	MAX_SHUTDOWN_SECS = 5
)

Variables

View Source
var RecordNotFound = errorf("record not found")

404 Response.

Functions

func Escape

func Escape(args map[string]interface{}) (s string, err error)

func GetIndexUrl

func GetIndexUrl(index string, _type string, id string, parentId string, version int, op_type string,
	routing string, timestamp string, ttl int, percolate string, timeout string, refresh bool) (retval string, e error)

func ScrollDuration

func ScrollDuration(duration string) string

func WriteBulkBytes

func WriteBulkBytes(op string, index string, _type string, id, ttl string, date *time.Time, data interface{}, refresh bool) ([]byte, error)

Given a set of arguments for index, type, id, data create a set of bytes that is formatted for bulkd index http://www.elasticsearch.org/guide/reference/api/bulk.html

Types

type AggregateDsl

type AggregateDsl struct {
	Name          string
	TypeName      string
	Type          interface{}
	Filters       *FilterWrap              `json:"filters,omitempty"`
	AggregatesVal map[string]*AggregateDsl `json:"aggregations,omitempty"`
}

func Aggregate

func Aggregate(name string) *AggregateDsl

func (*AggregateDsl) Aggregates

func (d *AggregateDsl) Aggregates(aggs ...*AggregateDsl) *AggregateDsl

*

  • Aggregates accepts n "sub-aggregates" to be applied to this aggregate *
  • agg := Aggregate("user").Term("user_id")
  • agg.Aggregates(
  • Aggregate("total_spent").Sum("price"),
  • Aggregate("total_saved").Sum("discount"),
  • )

func (*AggregateDsl) Avg

func (d *AggregateDsl) Avg(field string) *AggregateDsl

func (*AggregateDsl) Cardinality

func (d *AggregateDsl) Cardinality(field string, rehash bool, threshold int) *AggregateDsl

*

  • Cardinality(
  • "field_name",
  • true,
  • 0,
  • )

func (*AggregateDsl) DateHistogram

func (d *AggregateDsl) DateHistogram(field, interval string) *AggregateDsl

func (*AggregateDsl) ExtendedStats

func (d *AggregateDsl) ExtendedStats(field string) *AggregateDsl

func (*AggregateDsl) Filter

func (d *AggregateDsl) Filter(filters ...interface{}) *AggregateDsl

func (*AggregateDsl) Global

func (d *AggregateDsl) Global() *AggregateDsl

func (*AggregateDsl) Histogram

func (d *AggregateDsl) Histogram(field string, interval int) *AggregateDsl

func (*AggregateDsl) MarshalJSON

func (d *AggregateDsl) MarshalJSON() ([]byte, error)

func (*AggregateDsl) Max

func (d *AggregateDsl) Max(field string) *AggregateDsl

func (*AggregateDsl) Min

func (d *AggregateDsl) Min(field string) *AggregateDsl

func (*AggregateDsl) Missing

func (d *AggregateDsl) Missing(field string) *AggregateDsl

func (*AggregateDsl) Percentiles

func (d *AggregateDsl) Percentiles(field string) *AggregateDsl

func (*AggregateDsl) SignificantTerms

func (d *AggregateDsl) SignificantTerms(field string) *AggregateDsl

func (*AggregateDsl) Stats

func (d *AggregateDsl) Stats(field string) *AggregateDsl

func (*AggregateDsl) Sum

func (d *AggregateDsl) Sum(field string) *AggregateDsl

func (*AggregateDsl) Terms

func (d *AggregateDsl) Terms(field string) *AggregateDsl

func (*AggregateDsl) TermsWithSize

func (d *AggregateDsl) TermsWithSize(field string, size int) *AggregateDsl

func (*AggregateDsl) ValueCount

func (d *AggregateDsl) ValueCount(field string) *AggregateDsl

type AllocateCommand

type AllocateCommand struct {
	Index        string `json:"index"`
	Shard        string `json:"shard"`
	Node         string `json:"node"`
	AllowPrimary bool   `json:"allow_primary,omitempty"`
}

type AnalyzeResponse

type AnalyzeResponse struct {
	Tokens []Token `json:"tokens"`
}

type AnalyzerOptions

type AnalyzerOptions struct {
	Path  string `json:"path,omitempty"`
	Index string `json:"index,omitempty"`
}

type BaseResponse

type BaseResponse struct {
	Ok      bool             `json:"ok"`
	Index   string           `json:"_index,omitempty"`
	Type    string           `json:"_type,omitempty"`
	Id      string           `json:"_id,omitempty"`
	Source  *json.RawMessage `json:"_source,omitempty"` // depends on the schema you've defined
	Version int              `json:"_version,omitempty"`
	Found   bool             `json:"found,omitempty"`
	Exists  bool             `json:"exists,omitempty"`
	Created bool             `json:"created,omitempty"`
	Matches []string         `json:"matches,omitempty"` // percolate matches
}

type BoolClause

type BoolClause string

A bool (and/or) clause

type BulkIndexer

type BulkIndexer struct {

	// We are creating a variable defining the func responsible for sending
	// to allow a mock sendor for test purposes
	Sender func(*bytes.Buffer) error

	// If we encounter an error in sending, we are going to retry for this long
	// before returning an error
	// if 0 it will not retry
	RetryForSeconds int

	// channel for getting errors
	ErrorChannel chan *ErrorBuffer

	// Buffer for Max number of time before forcing flush
	BufferDelayMax time.Duration
	// Max buffer size in bytes before flushing to elasticsearch
	BulkMaxBuffer int // 1048576
	// Max number of Docs to hold in buffer before forcing flush
	BulkMaxDocs int // 100
	// contains filtered or unexported fields
}

A bulk indexer creates goroutines, and channels for connecting and sending data to elasticsearch in bulk, using buffers.

Example (Responses)

The inspecting the response

package main

import (
	"bytes"
	"fmt"

	elastigo "github.com/mattbaird/elastigo/lib"
	"strconv"
)

func main() {
	c := elastigo.NewConn()

	indexer := c.NewBulkIndexer(10)
	// Create a custom Sender Func, to allow inspection of response/error
	indexer.Sender = func(buf *bytes.Buffer) error {
		// @buf is the buffer of docs about to be written
		respJson, err := c.DoCommand("POST", "/_bulk", nil, buf)
		if err != nil {
			// handle it better than this
			fmt.Println(string(respJson))
		}
		return err
	}
	indexer.Start()
	for i := 0; i < 20; i++ {
		indexer.Index("twitter", "user", strconv.Itoa(i), "", nil, `{"name":"bob"}`, true)
	}
	indexer.Stop()
}
Output:

Example (Simple)

The simplest usage of background bulk indexing

package main

import (
	elastigo "github.com/mattbaird/elastigo/lib"
)

func main() {
	c := elastigo.NewConn()

	indexer := c.NewBulkIndexerErrors(10, 60)
	indexer.Start()
	indexer.Index("twitter", "user", "1", "", nil, `{"name":"bob"}`, true)
	indexer.Stop()
}
Output:

func (*BulkIndexer) Flush

func (b *BulkIndexer) Flush()

Flush all current documents to ElasticSearch

func (*BulkIndexer) Index

func (b *BulkIndexer) Index(index string, _type string, id, ttl string, date *time.Time, data interface{}, refresh bool) error

The index bulk API adds or updates a typed JSON document to a specific index, making it searchable. it operates by buffering requests, and ocassionally flushing to elasticsearch http://www.elasticsearch.org/guide/reference/api/bulk.html

func (*BulkIndexer) NumErrors

func (b *BulkIndexer) NumErrors() uint64

func (*BulkIndexer) PendingDocuments

func (b *BulkIndexer) PendingDocuments() int

func (*BulkIndexer) Send

func (b *BulkIndexer) Send(buf *bytes.Buffer) error

This does the actual send of a buffer, which has already been formatted into bytes of ES formatted bulk data

func (*BulkIndexer) Start

func (b *BulkIndexer) Start()

Starts this bulk Indexer running, this Run opens a go routine so is Non blocking

func (*BulkIndexer) Stop

func (b *BulkIndexer) Stop()

Stop stops the bulk indexer, blocking the caller until it is complete.

func (*BulkIndexer) Update

func (b *BulkIndexer) Update(index string, _type string, id, ttl string, date *time.Time, data interface{}, refresh bool) error

func (*BulkIndexer) UpdateWithPartialDoc

func (b *BulkIndexer) UpdateWithPartialDoc(index string, _type string, id, ttl string, date *time.Time, partialDoc interface{}, upsert bool, refresh bool) error

type CPU

type CPU struct {
	Vendor           string `json:"vendor,omitempty"`
	Model            string `json:"model,omitempty"`
	Mhz              int    `json:"mhz,omitempty"`
	TotalCores       int    `json:"total_cores,omitempty"`
	TotalSockets     int    `json:"total_sockets,omitempty"`
	CoresPerSocket   int    `json:"cores_per_socket,omitempty"`
	CacheSizeInBytes int    `json:"cache_size_in_bytes,omitempty"`
}

type CancelCommand

type CancelCommand struct {
	Index        string `json:"index"`
	Shard        string `json:"shard"`
	Node         string `json:"node"`
	AllowPrimary bool   `json:"allow_primary,omitempty"`
}

type Cardinality

type Cardinality struct {
	Field              string  `json:"field"`
	PrecisionThreshold float64 `json:"precision_threshold,omitempty"`
	Rehash             bool    `json:"rehash,omitempty"`
}

type Cluster

type Cluster struct {
	Name string `json:"name"`
}

type ClusterHealthResponse

type ClusterHealthResponse struct {
	ClusterName         string `json:"cluster_name"`
	Status              string `json:"status"`
	TimedOut            bool   `json:"timed_out"`
	NumberOfNodes       int    `json:"number_of_nodes"`
	NumberOfDataNodes   int    `json:"number_of_data_nodes"`
	ActivePrimaryShards int    `json:"active_primary_shards"`
	ActiveShards        int    `json:"active_shards"`
	RelocatingShards    int    `json:"relocating_shards"`
	InitializingShards  int    `json:"initializing_shards"`
	UnassignedShards    int    `json:"unassigned_shards"`
}

type ClusterSettingsResponse

type ClusterSettingsResponse struct {
	Transient  map[string]int `json:"transient"`
	Persistent map[string]int `json:"persistent"`
}

type ClusterStateFilter

type ClusterStateFilter struct {
	FilterNodes        bool
	FilterRoutingTable bool
	FilterMetadata     bool
	FilterBlocks       bool
	FilterIndices      []string
}

func (ClusterStateFilter) Parameterize

func (f ClusterStateFilter) Parameterize() []string

type ClusterStateIndiceResponse

type ClusterStateIndiceResponse struct {
	State string `json:"state"`
}

type ClusterStateMetadataResponse

type ClusterStateMetadataResponse struct {
	// TODO: templates
	Indices map[string]ClusterStateIndiceResponse `json:"indices"`
}

type ClusterStateNodeResponse

type ClusterStateNodeResponse struct {
	Name             string `json:"name"`
	TransportAddress string `json:"transport_address"`
}

type ClusterStateResponse

type ClusterStateResponse struct {
	ClusterName string                              `json:"cluster_name"`
	MasterNode  string                              `json:"master_node"`
	Nodes       map[string]ClusterStateNodeResponse `json:"nodes"`
	Metadata    ClusterStateMetadataResponse        `json:"metadata"`
}

type ClusterStateRoutingTableResponse

type ClusterStateRoutingTableResponse struct {
}

type Commands

type Commands struct {
	Commands []interface{} `json:"commands"`
}

type Conn

type Conn struct {
	// Maintain these for backwards compatibility
	Protocol       string
	Domain         string
	ClusterDomains []string
	Port           string
	Username       string
	Password       string
	Hosts          []string

	// To compute the weighting scores, we perform a weighted average of recent response times,
	// over the course of `DecayDuration`. DecayDuration may be set to 0 to use the default
	// value of 5 minutes. The EpsilonValueCalculator uses this to calculate a score
	// from the weighted average response time.
	DecayDuration time.Duration
	// contains filtered or unexported fields
}

func NewConn

func NewConn() *Conn

func (*Conn) AddAlias

func (c *Conn) AddAlias(index string, alias string) (BaseResponse, error)

The API allows you to create an index alias through an API.

func (*Conn) AllNodesInfo

func (c *Conn) AllNodesInfo() (NodeInfo, error)

The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information. information can be one of jvm, process

func (*Conn) AnalyzeIndices

func (c *Conn) AnalyzeIndices(index string, args map[string]interface{}) (AnalyzeResponse, error)

AnalyzeIndices performs the analysis process on a text and return the tokens breakdown of the text. http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/

func (*Conn) ClearCache

func (c *Conn) ClearCache(clearId bool, clearBloom bool, args map[string]interface{}, indices ...string) (ExtendedStatus, error)

ClearCache allows to clear either all caches or specific cached associated with one ore more indices. see http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/

func (*Conn) CloseIndex

func (c *Conn) CloseIndex(index string) (BaseResponse, error)

func (*Conn) ClusterState

func (c *Conn) ClusterState(filter ClusterStateFilter) (ClusterStateResponse, error)

func (*Conn) Count

func (c *Conn) Count(index string, _type string, args map[string]interface{}, query interface{}) (CountResponse, error)

Count allows the caller to easily execute a query and get the number of matches for that query. It can be executed across one or more indices and across one or more types. The query can either be provided using a simple query string as a parameter, or using the Query DSL defined within the request body. http://www.elasticsearch.org/guide/reference/api/count.html

func (*Conn) CreateIndex

func (c *Conn) CreateIndex(index string) (BaseResponse, error)

The create API allows you to create an indices through an API.

func (*Conn) CreateIndexWithSettings

func (c *Conn) CreateIndexWithSettings(index string, settings interface{}) (BaseResponse, error)

The create API allows you to create an indices through an API.

func (*Conn) Delete

func (c *Conn) Delete(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error)

Delete API allows to delete a typed JSON document from a specific index based on its id. http://www.elasticsearch.org/guide/reference/api/delete.html

func (*Conn) DeleteByQuery

func (c *Conn) DeleteByQuery(indices []string, types []string, args map[string]interface{}, query interface{}) (BaseResponse, error)

DeleteByQuery allows the caller to delete documents from one or more indices and one or more types based on a query. The query can either be provided using a simple query string as a parameter, or using the Query DSL defined within the request body. see: http://www.elasticsearch.org/guide/reference/api/delete-by-query.html

func (*Conn) DeleteIndex

func (c *Conn) DeleteIndex(index string) (BaseResponse, error)

The delete API allows you to delete one or more indices through an API. This operation may fail if the elasitsearch configuration has been set to forbid deleting indexes.

func (*Conn) DoCommand

func (c *Conn) DoCommand(method string, url string, args map[string]interface{}, data interface{}) ([]byte, error)

func (*Conn) Exists

func (c *Conn) Exists(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error)

Exists allows the caller to check for the existance of a document using HEAD This appears to be broken in the current version of elasticsearch 0.19.10, currently returning nothing

func (*Conn) ExistsBool

func (c *Conn) ExistsBool(index string, _type string, id string, args map[string]interface{}) (bool, error)

ExistsBool allows caller to check for the existence of a document using HEAD TODO(shutej): This looks redundant with the Exists function in baserequest.go, check with mattbaird@.

func (*Conn) ExistsIndex

func (c *Conn) ExistsIndex(index string, _type string, args map[string]interface{}) (bool, error)

ExistsIndex allows caller to check for the existance of an index or a type using HEAD

func (*Conn) Explain

func (c *Conn) Explain(index string, _type string, id string, args map[string]interface{}, query string) (Match, error)

Explain computes a score explanation for a query and a specific document. This can give useful feedback whether a document matches or didn’t match a specific query. This feature is available from version 0.19.9 and up. see http://www.elasticsearch.org/guide/reference/api/explain.html

func (*Conn) Flush

func (c *Conn) Flush(indices ...string) (BaseResponse, error)

Flush flushes one or more indices through an API. The flush process of an index basically frees memory from the index by flushing data to the index storage and clearing the internal transaction log. By default, ElasticSearch uses memory heuristics in order to automatically trigger flush operations as required in order to clear memory. http://www.elasticsearch.org/guide/reference/api/admin-indices-flush.html TODO: add Shards to response

func (*Conn) Get

func (c *Conn) Get(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error)

The get API allows to get a typed JSON document from the index based on its id. GET - retrieves the doc HEAD - checks for existence of the doc http://www.elasticsearch.org/guide/reference/api/get.html TODO: make this implement an interface

func (*Conn) GetCustom

func (c *Conn) GetCustom(index string, _type string, id string, args map[string]interface{}, source *json.RawMessage) (BaseResponse, error)

Same as Get but with custom source type.

func (*Conn) GetSource

func (c *Conn) GetSource(index string, _type string, id string, args map[string]interface{}, source interface{}) error

GetSource retrieves the document by id and converts it to provided interface

func (*Conn) Health

func (c *Conn) Health(indices ...string) (ClusterHealthResponse, error)

The cluster health API allows to get a very simple status on the health of the cluster. see http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html TODO: implement wait_for_status, timeout, wait_for_relocating_shards, wait_for_nodes TODO: implement level (Can be one of cluster, indices or shards. Controls the details level of the health information returned. Defaults to cluster.)

func (*Conn) Index

func (c *Conn) Index(index string, _type string, id string, args map[string]interface{}, data interface{}) (BaseResponse, error)

Index adds or updates a typed JSON document in a specific index, making it searchable, creating an index if it did not exist. if id is omited, op_type 'create' will be passed and http method will default to "POST" _type is optional id is optional parentId is optional version is optional op_type is optional routing is optional timestamp is optional ttl is optional percolate is optional timeout is optional http://www.elasticsearch.org/guide/reference/api/index_.html

func (*Conn) IndexWithParameters

func (c *Conn) IndexWithParameters(index string, _type string, id string, parentId string, version int, op_type string,
	routing string, timestamp string, ttl int, percolate string, timeout string, refresh bool,
	args map[string]interface{}, data interface{}) (BaseResponse, error)

IndexWithParameters takes all the potential parameters available

func (*Conn) IndicesExists

func (c *Conn) IndicesExists(indices ...string) (bool, error)

IndicesExists checks for the existance of indices. uses RecordNotFound message if it doesn't exist and "no error" situation if it exists. If there is some other error, gives the error and says it exists just in case see http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/

func (*Conn) MGet

func (c *Conn) MGet(index string, _type string, mgetRequest MGetRequestContainer, args map[string]interface{}) (MGetResponseContainer, error)

MGet allows the caller to get multiple documents based on an index, type (optional) and id (and possibly routing). The response includes a docs array with all the fetched documents, each element similar in structure to a document provided by the get API. see http://www.elasticsearch.org/guide/reference/api/multi-get.html

func (*Conn) MoreLikeThis

func (c *Conn) MoreLikeThis(index string, _type string, id string, args map[string]interface{}, query MoreLikeThisQuery) (BaseResponse, error)

MoreLikeThis allows the caller to get documents that are “like” a specified document. http://www.elasticsearch.org/guide/reference/api/more-like-this.html

func (*Conn) NewBulkIndexer

func (c *Conn) NewBulkIndexer(maxConns int) *BulkIndexer

func (*Conn) NewBulkIndexerErrors

func (c *Conn) NewBulkIndexerErrors(maxConns, retrySeconds int) *BulkIndexer

A bulk indexer with more control over error handling

 @maxConns is the max number of in flight http requests
 @retrySeconds is # of seconds to wait before retrying falied requests

done := make(chan bool)
BulkIndexerGlobalRun(100, done)

func (*Conn) NewRequest

func (c *Conn) NewRequest(method, path, query string) (*Request, error)

func (*Conn) NodesInfo

func (c *Conn) NodesInfo(information []string, nodes ...string) (NodeInfo, error)

func (*Conn) NodesShutdown

func (c *Conn) NodesShutdown(delay int, nodes ...string) error

NodesShutdown allows the caller to shutdown between one and all nodes in the cluster delay is a integer representing number of seconds passing "" or "_all" for the nodes parameter will shut down all nodes see http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-shutdown/

func (*Conn) NodesStats

func (c *Conn) NodesStats() (NodeStatsResponse, error)

func (*Conn) OpenIndex

func (c *Conn) OpenIndex(index string) (BaseResponse, error)

func (*Conn) OptimizeIndices

func (c *Conn) OptimizeIndices(args map[string]interface{}, indices ...string) (ExtendedStatus, error)

AnalyzeIndices performs the analysis process on a text and return the tokens breakdown of the text. http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/

func (*Conn) Percolate

func (c *Conn) Percolate(index string, _type string, name string, args map[string]interface{}, doc string) (Match, error)

func (*Conn) PutMapping

func (c *Conn) PutMapping(index string, typeName string, instance interface{}, opt MappingOptions) error

func (*Conn) PutSettings

func (c *Conn) PutSettings(index string, settings interface{}) (BaseResponse, error)

func (*Conn) Refresh

func (c *Conn) Refresh(indices ...string) (BaseResponse, error)

Refresh explicitly refreshes one or more index, making all operations performed since the last refresh available for search. The (near) real-time capabilities depend on the index engine used. For example, the internal one requires refresh to be called, but by default a refresh is scheduled periodically. http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh.html TODO: add Shards to response

func (*Conn) RegisterPercolate

func (c *Conn) RegisterPercolate(index string, name string, args map[string]interface{}, query OneTermQuery) (BaseResponse, error)

RegisterPercolate allows the caller to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. Think of it as the reverse operation of indexing and then searching. Instead of sending docs, indexing them, and then running queries. One sends queries, registers them, and then sends docs and finds out which queries match that doc. see http://www.elasticsearch.org/guide/reference/api/percolate.html

func (*Conn) Reroute

func (c *Conn) Reroute(dryRun bool, commands Commands) (ClusterHealthResponse, error)

The cluster health API allows to get a very simple status on the health of the cluster. see http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html information returned. Defaults to cluster.)

func (*Conn) Scroll

func (c *Conn) Scroll(args map[string]interface{}, scroll_id string) (SearchResult, error)

func (*Conn) Search

func (c *Conn) Search(index string, _type string, args map[string]interface{}, query interface{}) (SearchResult, error)

Search performs a very basic search on an index via the request URI API.

params:

@index:  the elasticsearch index
@_type:  optional ("" if not used) search specific type in this index
@args:   a map of URL parameters. Allows all the URI-request parameters allowed by ElasticSearch.
@query:  this can be one of 3 types:
           1)  string value that is valid elasticsearch
           2)  io.Reader that can be set in body (also valid elasticsearch string syntax..)
           3)  other type marshalable to json (also valid elasticsearch json)

out, err := Search(true, "github", map[string]interface{} {"from" : 10}, qryType)

http://www.elasticsearch.org/guide/reference/api/search/uri-request.html

func (*Conn) SearchUri

func (c *Conn) SearchUri(index, _type string, args map[string]interface{}) (SearchResult, error)

SearchUri performs the simplest possible query in url string params:

@index:  the elasticsearch index
@_type:  optional ("" if not used) search specific type in this index
@args: a map of URL parameters. Most important one is q

out, err := SearchUri("github","", map[string]interface{} { "q" : `user:kimchy`})

produces a request like this: host:9200/github/_search?q=user:kimchy"

http://www.elasticsearch.org/guide/reference/api/search/uri-request.html

func (*Conn) SetHosts

func (c *Conn) SetHosts(newhosts []string)

func (*Conn) SetPort

func (c *Conn) SetPort(port string)

func (*Conn) Snapshot

func (c *Conn) Snapshot(indices ...string) (ExtendedStatus, error)

Snapshot allows to explicitly perform a snapshot through the gateway of one or more indices (backup them). By default, each index gateway periodically snapshot changes, though it can be disabled and be controlled completely through this API. see http://www.elasticsearch.org/guide/reference/api/admin-indices-gateway-snapshot/

func (*Conn) Status

func (c *Conn) Status(args map[string]interface{}, indices ...string) (BaseResponse, error)

Status lists status details of all indices or the specified index. http://www.elasticsearch.org/guide/reference/api/admin-indices-status.html

func (*Conn) Suggest

func (c *Conn) Suggest(index string, args map[string]interface{}, query interface{}) (SuggestResults, error)

func (*Conn) Update

func (c *Conn) Update(index string, _type string, id string, args map[string]interface{}, data interface{}) (BaseResponse, error)

Update updates a document based on a script provided. The operation gets the document (collocated with the shard) from the index, runs the script (with optional script language and parameters), and index back the result (also allows to delete, or ignore the operation). It uses versioning to make sure no updates have happened during the “get” and “reindex”. (available from 0.19 onwards). Note, this operation still means full reindex of the document, it just removes some network roundtrips and reduces chances of version conflicts between the get and the index. The _source field need to be enabled for this feature to work.

http://www.elasticsearch.org/guide/reference/api/update.html TODO: finish this, it's fairly complex

func (*Conn) UpdateSetting

func (c *Conn) UpdateSetting(args map[string]interface{}, filter_indices ...string) (ClusterStateResponse, error)

State gets the comprehensive state information for the whole cluster see http://www.elasticsearch.org/guide/reference/api/admin-cluster-state/

func (*Conn) UpdateSettings

func (c *Conn) UpdateSettings(settingType string, key string, value int) (ClusterSettingsResponse, error)

UpdateSettings allows to update cluster wide specific settings. Defaults to Transient setting Settings updated can either be persistent (applied cross restarts) or transient (will not survive a full cluster restart). http://www.elasticsearch.org/guide/reference/api/admin-cluster-update-settings.html

func (*Conn) UpdateWithPartialDoc

func (c *Conn) UpdateWithPartialDoc(index string, _type string, id string, args map[string]interface{}, doc interface{}, upsert bool) (BaseResponse, error)

UpdateWithPartialDoc updates a document based on partial document provided. The update API also support passing a partial document (since 0.20), which will be merged into the existing document (simple recursive merge, inner merging of objects, replacing core "keys/values" and arrays). If both doc and script is specified, then doc is ignored. Best is to put your field pairs of the partial document in the script itself.

http://www.elasticsearch.org/guide/reference/api/update.html

func (*Conn) UpdateWithScript

func (c *Conn) UpdateWithScript(index string, _type string, id string, args map[string]interface{}, script string, params interface{}) (BaseResponse, error)

UpdateWithScript updates a document based on a script provided. The operation gets the document (collocated with the shard) from the index, runs the script (with optional script language and parameters), and index back the result (also allows to delete, or ignore the operation). It uses versioning to make sure no updates have happened during the "get" and "reindex". (available from 0.19 onwards).

Note, this operation still means full reindex of the document, it just removes some network roundtrips and reduces chances of version conflicts between the get and the index. The _source field need to be enabled for this feature to work. http://www.elasticsearch.org/guide/reference/api/update.html

func (*Conn) Validate

func (c *Conn) Validate(index string, _type string, args map[string]interface{}) (BaseResponse, error)

Validate allows a user to validate a potentially expensive query without executing it. see http://www.elasticsearch.org/guide/reference/api/validate.html

func (*Conn) WaitForStatus

func (c *Conn) WaitForStatus(status string, timeout int, indices ...string) (ClusterHealthResponse, error)

type CountResponse

type CountResponse struct {
	Count int    `json:"count"`
	Shard Status `json:"_shards"`
}

type DateHistogram

type DateHistogram struct {
	Field    string `json:"field"`
	Interval string `json:"interval"`
}

type DeleteByQueryResponse

type DeleteByQueryResponse struct {
	Status   bool                   `json:"ok"`
	Indicies map[string]IndexStatus `json:"_indices"`
}

type ESError

type ESError struct {
	When time.Time
	What string
	Code int
}

ESError is an error implementation that includes a time, message, and code.

func (ESError) Error

func (e ESError) Error() string

type ErrorBuffer

type ErrorBuffer struct {
	Err error
	Buf *bytes.Buffer
}

type Explaination

type Explaination struct {
	Index string `json:"index"`
	Valid bool   `json:"valid"`
	Error string `json:"error"`
}

type Explanation

type Explanation struct {
	Value       float32        `json:"value"`
	Description string         `json:"description"`
	Details     []*Explanation `json:"details,omitempty"`
}

func (*Explanation) String

func (e *Explanation) String(indent string) string

type ExtendedStatus

type ExtendedStatus struct {
	Ok           StatusBool `json:"ok"`
	ShardsStatus Status     `json:"_shards"`
}

type FacetDsl

type FacetDsl struct {
	Terms  map[string]*Term     `json:"terms,omitempty"`
	Ranges map[string]*RangeDsl `json:"terms,omitempty"`
	// contains filtered or unexported fields
}

func Facet

func Facet() *FacetDsl
"facets": {
    "terms": {
		"terms": {
			"field": [
			  "@fields.category"
			],
			"size": 25
		}
    }
}
"facets": {
  "actors": { "terms": {"field": ["actor"],"size": "10" }}
  , "langauge": { "terms": {"field": ["repository.language"],"size": "10" }}
}

func (*FacetDsl) Fields

func (m *FacetDsl) Fields(fields ...string) *FacetDsl

func (*FacetDsl) MarshalJSON

func (m *FacetDsl) MarshalJSON() ([]byte, error)

func (*FacetDsl) Range

func (m *FacetDsl) Range(r *RangeDsl) *FacetDsl

func (*FacetDsl) Regex

func (m *FacetDsl) Regex(field, match string) *FacetDsl

func (*FacetDsl) Size

func (m *FacetDsl) Size(size string) *FacetDsl

func (*FacetDsl) Term

func (m *FacetDsl) Term(t *Term) *FacetDsl

type Facets

type Facets struct {
	Tag struct {
		Terms string `json:"terms"`
	} `json:"tag"`
}

type Failure

type Failure struct {
	Index  string    `json:"index"`
	Shard  StatusInt `json:"shard"`
	Reason string    `json:"reason"`
}

func (Failure) String

func (f Failure) String() string

type FieldAggregate

type FieldAggregate struct {
	Field string `json:"field"`
	Size  int    `json:"size,omitempty"`
}

type FilterClause

type FilterClause interface {
	String() string
}

Filter clause is either a boolClause or FilterOp

type FilterOp

type FilterOp struct {
	TermsMap    map[string][]interface{}          `json:"terms,omitempty"`
	Range       map[string]map[string]interface{} `json:"range,omitempty"`
	Exist       map[string]string                 `json:"exists,omitempty"`
	MisssingVal map[string]string                 `json:"missing,omitempty"`
	// contains filtered or unexported fields
}

func Filter

func Filter() *FilterOp

Filter Operation

Filter().Term("user","kimchy")

// we use variadics to allow n arguments, first is the "field" rest are values
Filter().Terms("user", "kimchy", "elasticsearch")

Filter().Exists("repository.name")

func Range

func Range() *FilterOp

A range is a special type of Filter operation

Range().Exists("repository.name")

func (*FilterOp) Add

func (f *FilterOp) Add(fop *FilterOp) *FilterOp

Add another Filterop, "combines" two filter ops into one

func (*FilterOp) Exists

func (f *FilterOp) Exists(name string) *FilterOp

func (*FilterOp) Field

func (f *FilterOp) Field(fld string) *FilterOp

func (*FilterOp) From

func (f *FilterOp) From(from string) *FilterOp

func (*FilterOp) Gt

func (f *FilterOp) Gt(gt interface{}) *FilterOp

func (*FilterOp) Lt

func (f *FilterOp) Lt(lt interface{}) *FilterOp

func (*FilterOp) Missing

func (f *FilterOp) Missing(name string) *FilterOp

func (*FilterOp) Terms

func (f *FilterOp) Terms(field string, values ...interface{}) *FilterOp

Filter Terms

Filter().Terms("user","kimchy")

// we use variadics to allow n arguments, first is the "field" rest are values
Filter().Terms("user", "kimchy", "elasticsearch")

func (*FilterOp) To

func (f *FilterOp) To(to string) *FilterOp

type FilterWrap

type FilterWrap struct {
	// contains filtered or unexported fields
}

A wrapper to allow for custom serialization

func CompoundFilter

func CompoundFilter(fl ...interface{}) *FilterWrap

func NewFilterWrap

func NewFilterWrap() *FilterWrap

func (*FilterWrap) MarshalJSON

func (f *FilterWrap) MarshalJSON() ([]byte, error)

Custom marshalling to support the query dsl

func (*FilterWrap) String

func (f *FilterWrap) String() string

type Float32Nullable

type Float32Nullable float32

Elasticsearch returns some invalid (according to go) json, with floats having...

json: cannot unmarshal null into Go value of type float32 (see last field.)

"hits":{"total":6808,"max_score":null,

"hits":[{"_index":"10user","_type":"user","_id":"751820","_score":null,

func (*Float32Nullable) UnmarshalJSON

func (i *Float32Nullable) UnmarshalJSON(data []byte) error

type Highlight

type Highlight map[string][]string

type Histogram

type Histogram struct {
	Field    string  `json:"field"`
	Interval float64 `json:"interval"`
}

type Hit

type Hit struct {
	Index       string           `json:"_index"`
	Type        string           `json:"_type,omitempty"`
	Id          string           `json:"_id"`
	Score       Float32Nullable  `json:"_score,omitempty"` // Filters (no query) dont have score, so is null
	Source      *json.RawMessage `json:"_source"`          // marshalling left to consumer
	Fields      *json.RawMessage `json:"fields"`           // when a field arg is passed to ES, instead of _source it returns fields
	Explanation *Explanation     `json:"_explanation,omitempty"`
	Highlight   *Highlight       `json:"highlight,omitempty"`
}

type Hits

type Hits struct {
	Total int `json:"total"`
	//	MaxScore float32 `json:"max_score"`
	Hits []Hit `json:"hits"`
}

func (*Hits) Len

func (h *Hits) Len() int

type Http

type Http struct {
	BoundAddress   string `json:"bound_address,omitempty"`
	PublishAddress string `json:"publish_address,omitempty"`
}

type IdOptions

type IdOptions struct {
	Index string `json:"index,omitempty"`
	Path  string `json:"path,omitempty"`
}

type IndexStatus

type IndexStatus struct {
	Shards Status `json:"_shards"`
}

type Interface

type Interface struct {
	Address    string `json:"address,omitempty"`
	Name       string `json:"name,omitempty"`
	MacAddress string `json:"mac_address,omitempty"`
}

type JVM

type JVM struct {
	Pid          int      `json:"pid,omitempty"`
	Version      string   `json:"version,omitempty"`
	VMName       string   `json:"vm_name,omitempty"`
	VMVersion    string   `json:"vm_version,omitempty"`
	VMVendor     string   `json:"vm_vendor,omitempty"`
	StartTime    int      `json:"start_time,omitempty"`
	Mem          *JvmMem  `json:"mem,omitempty"`
	GcCollectors []string `json:"gc_collectors,omitempty"`
	MemoryPools  []string `json:"memory_pools,omitempty"`
}

type JsonAlias

type JsonAlias struct {
	Index string `json:"index"`
	Alias string `json:"alias"`
}

type JsonAliasAdd

type JsonAliasAdd struct {
	Add JsonAlias `json:"add"`
}

type JsonAliases

type JsonAliases struct {
	Actions []JsonAliasAdd `json:"actions"`
}

type JvmMem

type JvmMem struct {
	HeapInitInBytes    int `json:"heap_init_in_bytes,omitempty"`
	HeapMaxInBytes     int `json:"heap_max_in_bytes,omitempty"`
	NonHeapInitInBytes int `json:"non_heap_init_in_bytes,omitempty"`
	NonHeapMaxInBytes  int `json:"non_heap_max_in_bytes,omitempty"`
	DirectMaxInBytes   int `json:"direct_max_in_bytes,omitempty"`
}

type MEM

type MEM struct {
	TotalInBytes int `json:"total_in_bytes,omitempty"`
}

type MGetRequest

type MGetRequest struct {
	Index  string   `json:"_index"`
	Type   string   `json:"_type"`
	ID     string   `json:"_id"`
	IDS    []string `json:"_ids,omitempty"`
	Fields []string `json:"fields,omitempty"`
}

type MGetRequestContainer

type MGetRequestContainer struct {
	Docs []MGetRequest `json:"docs"`
}

type MGetResponseContainer

type MGetResponseContainer struct {
	Docs []BaseResponse `json:"docs"`
}

type MLT

type MLT struct {
	Fields              []string `json:"fields"`
	LikeText            string   `json:"like_text"`
	PercentTermsToMatch float32  `json:"percent_terms_to_match"`
	MinTermFrequency    int      `json:"min_term_freq"`
	MaxQueryTerms       int      `json:"max_query_terms"`
	StopWords           []string `json:"stop_words"`
	MinDocFrequency     int      `json:"min_doc_freq"`
	MaxDocFrequency     int      `json:"max_doc_freq"`
	MinWordLength       int      `json:"min_word_len"`
	MaxWordLength       int      `json:"max_word_len"`
	BoostTerms          int      `json:"boost_terms"`
	Boost               float32  `json:"boost"`
	Analyzer            string   `json:"analyzer"`
}

type Mapping

type Mapping map[string]MappingOptions

func MappingForType

func MappingForType(typeName string, opts MappingOptions) Mapping

func (Mapping) Options

func (m_ Mapping) Options() MappingOptions

type MappingOptions

type MappingOptions struct {
	Id         IdOptions              `json:"_id"`
	Timestamp  TimestampOptions       `json:"_timestamp"`
	Analyzer   *AnalyzerOptions       `json:"_analyzer,omitempty"`
	Parent     *ParentOptions         `json:"_parent,omitempty"`
	Routing    *RoutingOptions        `json:"_routing,omitempty"`
	Size       *SizeOptions           `json:"_size,omitempty"`
	Source     *SourceOptions         `json:"_source,omitempty"`
	Type       *TypeOptions           `json:"_type,omitempty"`
	Properties map[string]interface{} `json:"properties"`
}

type Match

type Match struct {
	OK          bool         `json:"ok"`
	Matches     []string     `json:"matches"`
	Explanation *Explanation `json:"explanation,omitempty"`
}

type MatchAll

type MatchAll struct {
	All string `json:"-"`
}

type MoreLikeThisQuery

type MoreLikeThisQuery struct {
	MoreLikeThis MLT `json:"more_like_this"`
}

type MoveCommand

type MoveCommand struct {
	Index    string `json:"index"`
	Shard    string `json:"shard"`
	FromNode string `json:"from_node"`
	ToNode   string `json:"to_node"`
}

type Network

type Network struct {
	RefreshInterval  int        `json:"refresh_interval,omitempty"`
	PrimaryInterface *Interface `json:"primary_interface,omitempty"`
}

type Node

type Node struct {
	Name             string      `json:"name,omitempty"`
	TransportAddress string      `json:"transport_address,omitempty"`
	Host             string      `json:"host,omitempty"`
	Ip               string      `json:"ip,omitempty"`
	Version          string      `json:"version,omitempty"`
	Build            string      `json:"build,omitempty"`
	Hostname         string      `json:"hostname,omitempty"`
	HttpAddress      string      `json:"http_address,omitempty"`
	Settings         *Settings   `json:"settings,omitempty"`
	OS               *OS         `json:"os,omitempty"`
	Process          *Process    `json:"process,omitempty"`
	JVM              *JVM        `json:"jvm,omitempty"`
	ThreadPool       *ThreadPool `json:"thread_pool,omitempty"`
	Network          *Network    `json:"network,omitempty"`
	Transport        *Transport  `json:"transport,omitempty"`
	Http             *Http       `json:"http,omitempty"`
	Plugins          []*Plugin   `json:"plugins,omitempty"`
}

type NodeInfo

type NodeInfo struct {
	ClusterName string          `json:"cluster_name"`
	Nodes       map[string]Node `json:"nodes"` // node name is random string
}

type NodeStatsFSDataResponse

type NodeStatsFSDataResponse struct {
	Path          string `json:"path"`
	Mount         string `json:"mount"`
	Device        string `json:"dev"`
	Total         int64  `json:"total_in_bytes"`
	Free          int64  `json:"free_in_bytes"`
	Available     int64  `json:"available_in_bytes"`
	DiskReads     int64  `json:"disk_reads"`
	DiskWrites    int64  `json:"disk_writes"`
	DiskReadSize  int64  `json:"disk_read_size_in_bytes"`
	DiskWriteSize int64  `json:"disk_write_size_in_bytes"`
}

type NodeStatsFSResponse

type NodeStatsFSResponse struct {
	Timestamp int64                     `json:"timestamp"`
	Data      []NodeStatsFSDataResponse `json:"data"`
}

type NodeStatsHTTPResponse

type NodeStatsHTTPResponse struct {
	CurrentOpen int64 `json:"current_open"`
	TotalOpen   int64 `json:"total_open"`
}

type NodeStatsIndicesDocsResponse

type NodeStatsIndicesDocsResponse struct {
	Count   int64 `json:"count"`
	Deleted int64 `json:"deleted"`
}

type NodeStatsIndicesGetResponse

type NodeStatsIndicesGetResponse struct {
	Total        int64 `json:"total"`
	Time         int64 `json:"time_in_millis"`
	ExistsTotal  int64 `json:"exists_total"`
	ExistsTime   int64 `json:"exists_time_in_millis"`
	MissingTotal int64 `json:"missing_total"`
	MissingTime  int64 `json:"missing_time_in_millis"`
	Current      int64 `json:"current"`
}

type NodeStatsIndicesIndexingResponse

type NodeStatsIndicesIndexingResponse struct {
	IndexTotal    int64 `json:"index_total"`
	IndexTime     int64 `json:"index_time_in_millis"`
	IndexCurrent  int64 `json:"index_current"`
	DeleteTotal   int64 `json:"delete_total"`
	DeleteTime    int64 `json:"delete_time_in_millis"`
	DeleteCurrent int64 `json:"delete_current"`
}

type NodeStatsIndicesSearchResponse

type NodeStatsIndicesSearchResponse struct {
	OpenContext  int64 `json:"open_contexts"`
	QueryTotal   int64 `json:"query_total"`
	QueryTime    int64 `json:"query_time_in_millis"`
	QueryCurrent int64 `json:"query_current"`
	FetchTotal   int64 `json:"fetch_total"`
	FetchTime    int64 `json:"fetch_time_in_millis"`
	FetchCurrent int64 `json:"fetch_current"`
}

type NodeStatsIndicesStoreResponse

type NodeStatsIndicesStoreResponse struct {
	Size         int64 `json:"size_in_bytes"`
	ThrottleTime int64 `json:"throttle_time_in_millis"`
}

type NodeStatsNetworkResponse

type NodeStatsNetworkResponse struct {
	TCP NodeStatsTCPResponse `json:"tcp"`
}

type NodeStatsNodeResponse

type NodeStatsNodeResponse struct {
	Name             string                                     `json:"name"`
	Timestamp        int64                                      `json:"timestamp"`
	TransportAddress string                                     `json:"transport_address"`
	Hostname         string                                     `json:"hostname"`
	Indices          NodeStatsIndicesResponse                   `json:"indices"`
	OS               NodeStatsOSResponse                        `json:"os"`
	Network          NodeStatsNetworkResponse                   `json:"network"`
	FS               NodeStatsFSResponse                        `json:"fs"`
	ThreadPool       map[string]NodeStatsThreadPoolPoolResponse `json:"thread_pool"`
}

type NodeStatsOSCPUResponse

type NodeStatsOSCPUResponse struct {
	Sys   int64 `json:"sys"`
	User  int64 `json:"user"`
	Idle  int64 `json:"idle"`
	Steal int64 `json:"stolen"`
}

type NodeStatsOSMemResponse

type NodeStatsOSMemResponse struct {
	Free       int64 `json:"free_in_bytes"`
	Used       int64 `json:"used_in_bytes"`
	ActualFree int64 `json:"actual_free_in_bytes"`
	ActualUsed int64 `json:"actual_used_in_bytes"`
}

type NodeStatsOSResponse

type NodeStatsOSResponse struct {
	Timestamp int64                   `json:"timestamp"`
	Uptime    int64                   `json:"uptime_in_millis"`
	LoadAvg   []float64               `json:"load_average"`
	CPU       NodeStatsOSCPUResponse  `json:"cpu"`
	Mem       NodeStatsOSMemResponse  `json:"mem"`
	Swap      NodeStatsOSSwapResponse `json:"swap"`
}

type NodeStatsOSSwapResponse

type NodeStatsOSSwapResponse struct {
	Used int64 `json:"used_in_bytes"`
	Free int64 `json:"free_in_bytes"`
}

type NodeStatsProcessCPUResponse

type NodeStatsProcessCPUResponse struct {
	Percent int64 `json:"percent"`
	Sys     int64 `json:"sys_in_millis"`
	User    int64 `json:"user_in_millis"`
	Total   int64 `json:"total_in_millis"`
}

type NodeStatsProcessMemResponse

type NodeStatsProcessMemResponse struct {
	Resident     int64 `json:"resident_in_bytes"`
	Share        int64 `json:"share_in_bytes"`
	TotalVirtual int64 `json:"total_virtual_in_bytes"`
}

type NodeStatsProcessResponse

type NodeStatsProcessResponse struct {
	Timestamp int64                       `json:"timestamp"`
	OpenFD    int64                       `json:"open_file_descriptors"`
	CPU       NodeStatsProcessCPUResponse `json:"cpu"`
	Memory    NodeStatsProcessMemResponse `json:"mem"`
}

type NodeStatsResponse

type NodeStatsResponse struct {
	ClusterName string `json:"cluster_name"`
	Nodes       map[string]NodeStatsNodeResponse
}

type NodeStatsTCPResponse

type NodeStatsTCPResponse struct {
	ActiveOpens  int64 `json:"active_opens"`
	PassiveOpens int64 `json:"passive_opens"`
	CurrEstab    int64 `json:"curr_estab"`
	InSegs       int64 `json:"in_segs"`
	OutSegs      int64 `json:"out_segs"`
	RetransSegs  int64 `json:"retrans_segs"`
	EstabResets  int64 `json:"estab_resets"`
	AttemptFails int64 `json:"attempt_fails"`
	InErrs       int64 `json:"in_errs"`
	OutRsts      int64 `json:"out_rsts"`
}

type NodeStatsThreadPoolPoolResponse

type NodeStatsThreadPoolPoolResponse struct {
	Threads   int64 `json:"threads"`
	Queue     int64 `json:"queue"`
	Active    int64 `json:"active"`
	Rejected  int64 `json:"rejected"`
	Largest   int64 `json:"largest"`
	Completed int64 `json:"completed"`
}

type NodeStatsTransportResponse

type NodeStatsTransportResponse struct {
	ServerOpen int64 `json:"server_open"`
	RxCount    int64 `json:"rx_count"`
	RxSize     int64 `json:"rx_size_in_bytes"`
	TxCount    int64 `json:"tx_count"`
	TxSize     int64 `json:"tx_size_in_bytes"`
}

type OS

type OS struct {
	RefreshInterval     int `json:"refresh_interval,omitempty"`
	AvailableProcessors int `json:"available_processors,omitempty"`
}

type OneTermQuery

type OneTermQuery struct {
	Query struct {
		Term string `json:"term"`
	} `json:"query"`
}

type ParentOptions

type ParentOptions struct {
	Type string `json:"type"`
}

type Path

type Path struct {
	Logs string `json:"logs,omitempty"`
	// contains filtered or unexported fields
}

type Plugin

type Plugin struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Site        bool   `json:"site,omitempty"`
	Jvm         bool   `json:"jvm,omitempty"`
	Url         string `json:"url,omitempty"`
}

type Process

type Process struct {
	RefreshInterval    int  `json:"refresh_interval,omitempty"`
	Id                 int  `json:"id,omitempty"`
	MaxFileDescriptors int  `json:"max_file_descriptors,omitempty"`
	Mlockall           bool `json:"mlockall,omitempty"`
}

type QueryDsl

type QueryDsl struct {
	QueryEmbed
	FilterVal *FilterOp `json:"filter,omitempty"`
}

some ways to serialize

"query": {
	"filtered": {
	  "query": {
	    "query_string": {
	      "default_operator": "OR",
	      "default_field": "_all",
	      "query": " actor:\"bob\"  AND type:\"EventType\""
	    }
	  },
	  "filter": {
	    "range": {
	      "@timestamp": {
	        "from": "2012-12-29T16:52:48+00:00",
	        "to": "2012-12-29T17:52:48+00:00"
	      }
	    }
	  }
	}
},
"query" : {
    "term" : { "user" : "kimchy" }
}
"query" : {
    "match_all" : {}
},

func Query

func Query() *QueryDsl

Query creates a new Query Dsl

func (*QueryDsl) All

func (q *QueryDsl) All() *QueryDsl

get all

func (*QueryDsl) Fields

func (q *QueryDsl) Fields(fields, search, exists, missing string) *QueryDsl

Fields in query_string search

Fields("fieldname","search_for","","")

Fields("fieldname,field2,field3","search_for","","")

Fields("fieldname,field2,field3","search_for","field_exists","")

func (*QueryDsl) Filter

func (q *QueryDsl) Filter(f *FilterOp) *QueryDsl

Filter this query

func (*QueryDsl) MarshalJSON

func (qd *QueryDsl) MarshalJSON() ([]byte, error)

MarshalJSON provides custom marshalling to support the query dsl which is a conditional json format, not always the same parent/children

func (*QueryDsl) Qs

func (q *QueryDsl) Qs(qs *QueryString) *QueryDsl

Querystring operations

func (*QueryDsl) Range

func (q *QueryDsl) Range(fop *FilterOp) *QueryDsl

Limit the query to this range

func (*QueryDsl) Search

func (q *QueryDsl) Search(searchFor string) *QueryDsl

The raw search strings (lucene valid)

func (*QueryDsl) Term

func (q *QueryDsl) Term(name, value string) *QueryDsl

Add a term search for a specific field

Term("user","kimchy")

type QueryEmbed

type QueryEmbed struct {
	MatchAll *MatchAll         `json:"match_all,omitempty"`
	Terms    map[string]string `json:"term,omitempty"`
	Qs       *QueryString      `json:"query_string,omitempty"`
}

The core Query Syntax can be embedded as a child of a variety of different parents

type QueryString

type QueryString struct {
	DefaultOperator string   `json:"default_operator,omitempty"`
	DefaultField    string   `json:"default_field,omitempty"`
	Query           string   `json:"query,omitempty"`
	Exists          string   `json:"_exists_,omitempty"`
	Missing         string   `json:"_missing_,omitempty"`
	Fields          []string `json:"fields,omitempty"`
}

func NewQueryString

func NewQueryString(field, query string) QueryString

QueryString based search

type QueryWrap

type QueryWrap struct {
	Qs QueryString `json:"query_string,omitempty"`
}

should we reuse QueryDsl here?

type RangeDef

type RangeDef struct {
	Field  string      `json:"field,omitempty"`
	Values []*RangeVal `json:"ranges,omitempty"`
}

type RangeDsl

type RangeDsl struct {
	RangeDef  *RangeDef   `json:"range,omitempty"`
	FilterVal *FilterWrap `json:"facet_filter,omitempty"`
}

func FacetRange

func FacetRange(field string) *RangeDsl

func (*RangeDsl) Filter

func (s *RangeDsl) Filter(fl ...interface{}) *RangeDsl

func (*RangeDsl) Range

func (m *RangeDsl) Range(from, to string) *RangeDsl

type RangeVal

type RangeVal struct {
	From string `json:"from,omitempty"`
	To   string `json:"to,omitempty"`
}

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func (*Request) Do

func (r *Request) Do(v interface{}) (int, []byte, error)

func (*Request) DoResponse

func (r *Request) DoResponse(v interface{}) (*http.Response, []byte, error)

func (*Request) SetBody

func (r *Request) SetBody(body io.Reader)

func (*Request) SetBodyBytes

func (r *Request) SetBodyBytes(body []byte)

func (*Request) SetBodyJson

func (r *Request) SetBodyJson(data interface{}) error

func (*Request) SetBodyString

func (r *Request) SetBodyString(body string)

type RoutingOptions

type RoutingOptions struct {
	Required bool   `json:"required,omitempty"`
	Path     string `json:"path,omitempty"`
}

type SWAP

type SWAP struct {
	TotalInBytes int `json:"total_in_bytes,omitempty"`
}

type SearchDsl

type SearchDsl struct {
	FromVal       int                      `json:"from,omitempty"`
	SizeVal       int                      `json:"size,omitempty"`
	Index         string                   `json:"-"`
	FacetVal      *FacetDsl                `json:"facets,omitempty"`
	QueryVal      *QueryDsl                `json:"query,omitempty"`
	SortBody      []*SortDsl               `json:"sort,omitempty"`
	FilterVal     *FilterWrap              `json:"filter,omitempty"`
	AggregatesVal map[string]*AggregateDsl `json:"aggregations,omitempty"`
	// contains filtered or unexported fields
}
func Search(index string) *SearchDsl

Search is the entry point to the SearchDsl, it is a chainable set of utilities to create searches.

params

@index = elasticsearch index to search

out, err := Search("github").Type("Issues").Pretty().Query(
Query().Range(
     Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
   ).Search("add"),
 ).Result()

func (*SearchDsl) Aggregates

func (s *SearchDsl) Aggregates(aggs ...*AggregateDsl) *SearchDsl

func (*SearchDsl) Bytes

func (s *SearchDsl) Bytes(conn *Conn) ([]byte, error)

func (*SearchDsl) Facet

func (s *SearchDsl) Facet(f *FacetDsl) *SearchDsl

Facet passes a Query expression to this search

qry := Search("github").Size("0").Facet(
			Facet().Regex("repository.name", "no.*").Size("8"),
		)

qry := Search("github").Pretty().Facet(
			Facet().Fields("type").Size("25"),
		)

func (*SearchDsl) Fields

func (s *SearchDsl) Fields(fields ...string) *SearchDsl

func (*SearchDsl) Filter

func (s *SearchDsl) Filter(fl ...interface{}) *SearchDsl

Filter adds a Filter Clause with optional Boolean Clause. This accepts n number of filter clauses. If more than one, and missing Boolean Clause it assumes "and"

qry := Search("github").Filter(
    Filter().Exists("repository.name"),
)

qry := Search("github").Filter(
    "or",
    Filter().Exists("repository.name"),
    Filter().Terms("actor_attributes.location", "portland"),
)

qry := Search("github").Filter(
    Filter().Exists("repository.name"),
    Filter().Terms("repository.has_wiki", true)
)

func (*SearchDsl) From

func (s *SearchDsl) From(from string) *SearchDsl

func (*SearchDsl) Pretty

func (s *SearchDsl) Pretty() *SearchDsl

func (*SearchDsl) Query

func (s *SearchDsl) Query(q *QueryDsl) *SearchDsl

func (*SearchDsl) Result

func (s *SearchDsl) Result(conn *Conn) (*SearchResult, error)

func (*SearchDsl) Scroll

func (s *SearchDsl) Scroll(duration string) *SearchDsl

func (*SearchDsl) Search

func (s *SearchDsl) Search(srch string) *SearchDsl

Search is a simple interface to search, doesn't have the power of query but uses a simple query_string search

func (*SearchDsl) Size

func (s *SearchDsl) Size(size string) *SearchDsl

func (*SearchDsl) Sort

func (s *SearchDsl) Sort(sort ...*SortDsl) *SearchDsl

func (*SearchDsl) Source

func (s *SearchDsl) Source(returnSource bool) *SearchDsl

func (*SearchDsl) Type

func (s *SearchDsl) Type(indexType string) *SearchDsl

Type is the elasticsearch *Type* within a specific index

type SearchRequest

type SearchRequest struct {
	From  int          `json:"from,omitempty"`
	Size  int          `json:"size,omitempty"`
	Query OneTermQuery `json:"query,omitempty"`

	Filter struct {
		Term Term `json:"term"`
	} `json:"filter,omitempty"`
}

type SearchResult

type SearchResult struct {
	RawJSON      []byte
	Took         int             `json:"took"`
	TimedOut     bool            `json:"timed_out"`
	ShardStatus  Status          `json:"_shards"`
	Hits         Hits            `json:"hits"`
	Facets       json.RawMessage `json:"facets,omitempty"` // structure varies on query
	ScrollId     string          `json:"_scroll_id,omitempty"`
	Aggregations json.RawMessage `json:"aggregations,omitempty"` // structure varies on query
	Suggestions  Suggestions     `json:"suggest,omitempty"`
}

func (*SearchResult) String

func (s *SearchResult) String() string

type Settings

type Settings struct {
	Path       *Path  `json:"path,omitempty"`
	Foreground string `json:"foreground,omitempty"`
	Name       string `json:"name,omitempty"`
}

type SizeOptions

type SizeOptions struct {
	Enabled bool `json:"enabled,omitempty"`
	Store   bool `json:"store,omitempty"`
}

type SortBody

type SortBody []interface{}

type SortDsl

type SortDsl struct {
	Name   string
	IsDesc bool
}

func Sort

func Sort(field string) *SortDsl

SortDsl accepts any number of Sort commands

Query().Sort(
    Sort("last_name").Desc(),
    Sort("age"),
)

func (*SortDsl) Asc

func (s *SortDsl) Asc() *SortDsl

func (*SortDsl) Desc

func (s *SortDsl) Desc() *SortDsl

func (*SortDsl) MarshalJSON

func (s *SortDsl) MarshalJSON() ([]byte, error)

type SourceOptions

type SourceOptions struct {
	Enabled  bool     `json:"enabled,omitempty"`
	Includes []string `json:"includes,omitempty"`
	Excludes []string `json:"excludes,omitempty"`
}

type Status

type Status struct {
	Total      StatusInt `json:"total"`
	Successful StatusInt `json:"successful"`
	Failed     StatusInt `json:"failed"`
	Failures   []Failure `json:"failures,omitempty"`
}

type StatusBool

type StatusBool bool

StatusBool is required because /_optimize, at least, returns its status as strings instead of booleans.

func (*StatusBool) MarshalJSON

func (self *StatusBool) MarshalJSON() ([]byte, error)

func (*StatusBool) UnmarshalJSON

func (self *StatusBool) UnmarshalJSON(b []byte) error

type StatusInt

type StatusInt int

StatusInt is required because /_optimize, at least, returns its status as strings instead of integers.

func (*StatusInt) MarshalJSON

func (self *StatusInt) MarshalJSON() ([]byte, error)

func (*StatusInt) UnmarshalJSON

func (self *StatusInt) UnmarshalJSON(b []byte) error

type SuggestResults

type SuggestResults struct {
	ShardStatus Status
	// contains filtered or unexported fields
}

func (SuggestResults) Result

func (s SuggestResults) Result(suggestName string) ([]Suggestion, error)

type Suggestion

type Suggestion struct {
	Length  int                `json:"length"`
	Offset  int                `json:"offset"`
	Options []SuggestionOption `json:"options"`
	Text    string             `json:"text"`
}

type SuggestionOption

type SuggestionOption struct {
	Payload json.RawMessage `json:"payload"`
	Score   Float32Nullable `json:"score,omitempty"`
	Text    string          `json:"text"`
}

type Suggestions

type Suggestions map[string][]Suggestion

type Term

type Term struct {
	Terms     Terms       `json:"terms,omitempty"`
	FilterVal *FilterWrap `json:"facet_filter,omitempty"`
}

Generic Term based (used in query, facet, filter)

func NewTerm

func NewTerm(fields ...string) *Term

func (*Term) Filter

func (s *Term) Filter(fl ...interface{}) *Term

type Terms

type Terms struct {
	Fields []string `json:"field,omitempty"`
	Size   string   `json:"size,omitempty"`
	Regex  string   `json:"regex,omitempty"`
}

func (*Terms) MarshalJSON

func (t *Terms) MarshalJSON() ([]byte, error)

Custom marshalling

type ThreadPool

type ThreadPool struct {
	Generic    *ThreadPoolConfig `json:"generic,omitempty"`
	Index      *ThreadPoolConfig `json:"index,omitempty"`
	Get        *ThreadPoolConfig `json:"get,omitempty"`
	Snapshot   *ThreadPoolConfig `json:"snapshot,omitempty"`
	Merge      *ThreadPoolConfig `json:"merge,omitempty"`
	Suggest    *ThreadPoolConfig `json:"suggest,omitempty"`
	Bulk       *ThreadPoolConfig `json:"bulk,omitempty"`
	Optimize   *ThreadPoolConfig `json:"optimize,omitempty"`
	Warmer     *ThreadPoolConfig `json:"warmer,omitempty"`
	Flush      *ThreadPoolConfig `json:"flush,omitempty"`
	Search     *ThreadPoolConfig `json:"search,omitempty"`
	Percolate  *ThreadPoolConfig `json:"percolate,omitempty"`
	Management *ThreadPoolConfig `json:"management,omitempty"`
	Refresh    *ThreadPoolConfig `json:"refresh,omitempty"`
}

type ThreadPoolConfig

type ThreadPoolConfig struct {
	Type      string      `json:"type,omitempty"`
	Min       int         `json:"min,omitempty"`
	Max       int         `json:"max,omitempty"`
	QueueSize interface{} `json:"queue_size,omitempty"` // Either string or -1
	KeepAlive string      `json:"keep_alive,omitempty"`
}

type TimestampOptions

type TimestampOptions struct {
	Enabled bool `json:"enabled"`
}

type Token

type Token struct {
	Name        string `json:"token"`
	StartOffset int    `json:"start_offset"`
	EndOffset   int    `json:"end_offset"`
	Type        string `json:"type"`
	Position    int    `json:"position"`
}

type Transport

type Transport struct {
	BoundAddress   string `json:"bound_address,omitempty"`
	PublishAddress string `json:"publish_address,omitempty"`
}

type TypeOptions

type TypeOptions struct {
	Store bool   `json:"store,omitempty"`
	Index string `json:"index,omitempty"`
}

type Validation

type Validation struct {
	Valid         bool           `json:"valid"`
	Shards        Status         `json:"_shards"`
	Explainations []Explaination `json:"explanations,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL