search

package
v0.0.0-...-054c023 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2014 License: Apache-2.0 Imports: 8 Imported by: 0

README


To run tests on this, you must first have run/imported data inside of *core*

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

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

type BoolClause

type BoolClause string

A bool (and/or) clause

type Cardinality

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

type DateHistogram

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

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 FieldAggregate

type FieldAggregate struct {
	Field string `json:"field"`
}

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 int) *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 Histogram

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

type MatchAll

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

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

QueryDsl 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 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() ([]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() (*core.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 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 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

Jump to

Keyboard shortcuts

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