elasticsearch

package
v5.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: AGPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Internal provides elasticsearche's "internal" versioning system, as described in
	// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#_version_types
	Internal = "internal"

	// External provides elasticsearche's "external" versioning system, as described in
	// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#_version_types
	External = "external"

	// ExternalGTE provides elasticsearche's "external_gte" versioning system, as described in
	// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#_version_types
	ExternalGTE = "external_gte"
)

Variables

View Source
var Ascending = Order{"asc"}

Ascending is an Order that orders a sort by ascending through the values.

View Source
var Descending = Order{"desc"}

Descending is an Order that orders a sort by descending throuth the values.

View Source
var ErrConflict = errgo.New("elasticsearch document conflict")
View Source
var ErrNotFound = errgo.New("elasticsearch document not found")

Functions

func BoostField

func BoostField(field string, boost float64) string

BoostField creates a string which represents a field name with a boost value.

func EscapeRegexp

func EscapeRegexp(s string) string

EscapeRegexp returns the supplied string with any special characters escaped. A regular expression match on the returned string will match exactly the characters in the supplied string.

Types

type AndFilter

type AndFilter []Filter

AndFilter provides a filter that matches if all of the internal filters match.

func (AndFilter) MarshalJSON

func (a AndFilter) MarshalJSON() ([]byte, error)

type BoostFactorFunction

type BoostFactorFunction struct {
	Filter      Filter  `json:"filter,omitempty"`
	BoostFactor float64 `json:"boost_factor"`
}

BoostFactorFunction provides a function that boosts results by the specified amount.

type ClusterHealth

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

Represents the response from _cluster/health on elastic search http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html

func (*ClusterHealth) String

func (h *ClusterHealth) String() string

type Database

type Database struct {
	Addr string
}

func (*Database) Alias

func (db *Database) Alias(i, a string) error

Alias creates or updates an index alias. An alias a is created, or modified if it already exists, to point to i. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases for further details.

func (*Database) CreateDocument

func (db *Database) CreateDocument(index, type_, id string, doc interface{}) error

Create document attempts to create a new document at index/type_/id with the contents in doc. If the document already exists then CreateDocument will return ErrConflict and return a non-nil error if any other error occurs. See http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/create-doc.html#create-doc for further details.

func (*Database) DeleteDocument

func (db *Database) DeleteDocument(index, type_, id string) error

DeleteDocument deletes the document at index/type_/id from the elasticsearch database. See http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/delete-doc.html#delete-doc for further details.

func (*Database) DeleteIndex

func (db *Database) DeleteIndex(index string) error

DeleteIndex deletes the index with the given name from the database. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-delete-index.html If the index does not exist or if the database cannot be reached, then an error is returned.

func (*Database) GetDocument

func (db *Database) GetDocument(index, type_, id string, v interface{}) error

GetDocument retrieves the document with the given index, type_ and id and unmarshals the json response into v. GetDocument returns ErrNotFound if the requested document is not present, and returns a non-nil error if any other error occurs.

func (*Database) GetESDocument

func (db *Database) GetESDocument(index, type_, id string) (Document, error)

GetESDocument returns elasticsearch's view of the document stored at index/type_/id. It is not an error if this document does not exist, in that case the Found field of the returned Document will be false.

func (*Database) HasDocument

func (db *Database) HasDocument(index, type_, id string) (bool, error)

HasDocument tests to see a document of the given index, type_, and id exists in the elasticsearch database. A non-nil error is returned if there is an error communicating with the elasticsearch database.

func (*Database) Health

func (db *Database) Health() (ClusterHealth, error)

Check the health status of Elastic search and retrieve general data from it. Calling get on /_cluster/health to retrieve status.

func (*Database) ListAllIndexes

func (db *Database) ListAllIndexes() ([]string, error)

ListAllIndexes retreieves the list of all user indexes in the elasticsearch database. indexes that are generated to to support plugins are filtered out of the list that is returned.

func (*Database) ListIndexesForAlias

func (db *Database) ListIndexesForAlias(a string) ([]string, error)

ListIndexesForAlias retreieves the list of all indexes in the elasticsearch database that have the alias a.

func (*Database) PostDocument

func (db *Database) PostDocument(index, type_ string, doc interface{}) (string, error)

PostDocument creates a new auto id document with the given index and _type and returns the generated id of the document. The type_ parameter controls how the document will be mapped in the index. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html for more details.

func (*Database) PutDocument

func (db *Database) PutDocument(index, type_, id string, doc interface{}) error

PutDocument creates or updates the document with the given index, type_ and id. The type_ parameter controls how the document will be mapped in the index. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html for more details.

func (*Database) PutDocumentVersion

func (db *Database) PutDocumentVersion(index, type_, id string, version int64, doc interface{}) error

PutDocumentVersion creates or updates the document in the given index if the version parameter is the same as the currently stored version. The type_ parameter controls how the document will be indexed. PutDocumentVersion returns ErrConflict if the data cannot be stored due to a version mismatch, and a non-nil error if any other error occurs. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#index-versioning for more information.

func (*Database) PutDocumentVersionWithType

func (db *Database) PutDocumentVersionWithType(
	index, type_, id string,
	version int64,
	versionType string,
	doc interface{}) error

PutDocumentVersion creates or updates the document in the given index if the version parameter is the same as the currently stored version. The type_ parameter controls how the document will be indexed. PutDocumentVersionWithType returns ErrConflict if the data cannot be stored due to a version mismatch, and a non-nil error if any other error occurs.

The constants Internal, External and ExternalGTE represent some of the available version types. Other version types may also be available, plese check the elasticsearch documentation.

See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#index-versioning and http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#_version_types for more information.

func (*Database) PutIndex

func (db *Database) PutIndex(index string, config interface{}) error

PutIndex creates the index with the given configuration.

func (*Database) PutMapping

func (db *Database) PutMapping(index, type_ string, config interface{}) error

PutMapping creates or updates the mapping with the given configuration.

func (*Database) RefreshIndex

func (db *Database) RefreshIndex(index string) error

RefreshIndex posts a _refresh to the index in the database. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-refresh.html

func (*Database) Search

func (db *Database) Search(index, type_ string, q QueryDSL) (SearchResult, error)

Search performs the query specified in q on the values in index/type_ and returns a SearchResult.

type DecayFunction

type DecayFunction struct {
	Function string
	Field    string
	Scale    string
}

DecayFunction provides a function that boosts depending on the difference in values of a certain field. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_decay_functions for details.

func (DecayFunction) MarshalJSON

func (f DecayFunction) MarshalJSON() ([]byte, error)

type Document

type Document struct {
	Found   bool            `json:"found"`
	Id      string          `json:"_id"`
	Index   string          `json:"_index"`
	Type    string          `json:"_type"`
	Version int64           `json:"_version"`
	Source  json.RawMessage `json:"_source"`
}

Document represents a document in the elasticsearch database.

type ElasticSearchError

type ElasticSearchError struct {
	Err    string `json:"error"`
	Status int    `json:"status"`
}

func (ElasticSearchError) Error

func (e ElasticSearchError) Error() string

type ExistsFilter

type ExistsFilter string

ExistsFilter provides a filter that requres a field to be present.

func (ExistsFilter) MarshalJSON

func (f ExistsFilter) MarshalJSON() ([]byte, error)

type FieldValueFactorFunction

type FieldValueFactorFunction struct {
	Field    string  `json:"field"`
	Factor   float64 `json:"factor,omitempty"`
	Modifier string  `json:"modifier,omitempty"`
}

FieldValueFactorFunction boosts the results by the value of a field in the document.

func (FieldValueFactorFunction) MarshalJSON

func (f FieldValueFactorFunction) MarshalJSON() ([]byte, error)

type Fields

type Fields map[string][]interface{}

func (Fields) Get

func (f Fields) Get(key string) interface{}

Get retrieves the first value of key in the fields map. If no such value exists then it will return nil.

func (Fields) GetString

func (f Fields) GetString(key string) string

Get retrieves the first value of key in the fields map, and coerces it into a string. If no such value exists or the value is not a string, then "" will be returned.

type Filter

type Filter interface {
	json.Marshaler
}

Filter represents a filter in the elasticsearch DSL.

type FilteredQuery

type FilteredQuery struct {
	Query  Query
	Filter Filter
}

FilteredQuery provides a query that includes a filter.

func (FilteredQuery) MarshalJSON

func (f FilteredQuery) MarshalJSON() ([]byte, error)

type Function

type Function interface{}

Function is a function definition for use with a FunctionScoreQuery.

type FunctionScoreQuery

type FunctionScoreQuery struct {
	Query     Query
	Functions []Function
}

FunctionScoreQuery provides a query that adjusts the scoring of a query by applying functions to it.

func (FunctionScoreQuery) MarshalJSON

func (f FunctionScoreQuery) MarshalJSON() ([]byte, error)

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 Fields          `json:"fields"`
}

Hit represents an individual search hit returned from elasticsearch

type MatchAllQuery

type MatchAllQuery struct {
}

MatchAllQuery provides a query that matches all documents in the index.

func (MatchAllQuery) MarshalJSON

func (m MatchAllQuery) MarshalJSON() ([]byte, error)

type MatchQuery

type MatchQuery struct {
	Field    string
	Query    string
	Type     string
	Analyzer string
}

MatchQuery provides a query that matches against a complete field.

func (MatchQuery) MarshalJSON

func (m MatchQuery) MarshalJSON() ([]byte, error)

type MultiMatchQuery

type MultiMatchQuery struct {
	Query  string
	Fields []string

	// MinimumShouldMatch optionally contains the value for the
	// minimum_should_match parameter, For details of possible values
	// please see:
	// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
	MinimumShouldMatch string
}

MultiMatchQuery provides a query that matches on a number of fields.

func (MultiMatchQuery) MarshalJSON

func (m MultiMatchQuery) MarshalJSON() ([]byte, error)

type NotFilter

type NotFilter struct {
	Filter Filter
}

NotFilter provides a filter that matches the opposite of the wrapped filter.

func (NotFilter) MarshalJSON

func (n NotFilter) MarshalJSON() ([]byte, error)

type OrFilter

type OrFilter []Filter

OrFilter provides a filter that matches if any of the internal filters match.

func (OrFilter) MarshalJSON

func (o OrFilter) MarshalJSON() ([]byte, error)

type Order

type Order struct {
	Order string `json:"order"`
}

type Query

type Query interface {
	json.Marshaler
}

Query represents a query in the elasticsearch DSL.

type QueryDSL

type QueryDSL struct {
	Fields []string `json:"fields"`
	From   int      `json:"from,omitempty"`
	Size   int      `json:"size,omitempty"`
	Query  Query    `json:"query,omitempty"`
	Sort   []Sort   `json:"sort,omitempty"`
}

QueryDSL provides a structure to put together a query using the elasticsearch DSL.

type QueryFilter

type QueryFilter struct {
	Query Query
}

QueryFilter provides a filter that matches when a query matches on a result

func (QueryFilter) MarshalJSON

func (q QueryFilter) MarshalJSON() ([]byte, error)

type RegexpFilter

type RegexpFilter struct {
	Field  string
	Regexp string
}

RegexpFilter provides a filter that matches a field against a regular expression.

func (RegexpFilter) MarshalJSON

func (r RegexpFilter) MarshalJSON() ([]byte, error)

type SearchResult

type SearchResult struct {
	Hits struct {
		Total    int     `json:"total"`
		MaxScore float64 `json:"max_score"`
		Hits     []Hit   `json:"hits"`
	} `json:"hits"`
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
}

SearchResult is the result returned after performing a search in elasticsearch

type Sort

type Sort struct {
	Field string
	Order Order
}

func (Sort) MarshalJSON

func (s Sort) MarshalJSON() ([]byte, error)

type TermFilter

type TermFilter struct {
	Field string
	Value string
}

TermFilter provides a filter that requires a field to match.

func (TermFilter) MarshalJSON

func (t TermFilter) MarshalJSON() ([]byte, error)

type TermQuery

type TermQuery struct {
	Field string
	Value string
}

TermQuery provides a query that matches a term in a field.

func (TermQuery) MarshalJSON

func (t TermQuery) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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