elasticsearch

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2014 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 Database

type Database struct {
	Addr string
}

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) EnsureID

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

EnsureID tests to see a document of the given index, type_, and id exists in ElasticSearch.

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.

func (*Database) Index

func (db *Database) Index(name string) *Index

Index creates a reference to an index in the elasticsearch database.

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) 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{}) (bool, error)

PutDocumentVersion creates or updates the document with the given index if the version is equal or newer than the currently stored version. The type_ parameter controls how the document will be indexed. PutDocumentVersion returns a bool indicating if the data was stored and an error. If the data was not stored due to a version conflict the returned value will be false, nil. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html#index-versioning 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 ElasticSearchError

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

func (ElasticSearchError) Error

func (e ElasticSearchError) Error() string

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 Index

type Index struct {
	Database *Database
	Index    string
}

Index represents an index in the elasticsearch database.

func (*Index) Delete

func (i *Index) Delete() error

Delete deletes the index. This is a wrapper around Database.DeleteIndex.

func (*Index) GetDocument

func (i *Index) GetDocument(type_, id string, doc interface{}) error

GetDocument retrieves the document with the given type_ and id in the index. This is a wrapper around Database.GetDocument.

func (*Index) PutDocument

func (i *Index) PutDocument(type_, id string, doc interface{}) error

PutDocument creates or updates the document with the given type_ and id in the index. This is a wrapper around Database.PutDocument.

func (*Index) PutDocumentVersion

func (i *Index) PutDocumentVersion(type_, id string, version int64, doc interface{}) (bool, error)

PutDocumentVersion creates or updates the document with the given type_ and id in the index if the version is the same or newer than the currently store version. This is a wrapper around Database.PutDocumentVersion.

func (*Index) Search

func (i *Index) Search(type_ string, q QueryDSL) (SearchResult, error)

Search searches the index on the given type_ with the given QueryDSL. This is a wrapper around Database.Search

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
}

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
}

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