Documentation
¶
Index ¶
- Variables
- func SetLog(l *log.Logger)
- type Classifier
- type DocumentMapping
- func (dm *DocumentMapping) AddFieldMapping(fm *FieldMapping)
- func (dm *DocumentMapping) AddFieldMappingsAt(property string, fms ...*FieldMapping)
- func (dm *DocumentMapping) AddSubDocumentMapping(property string, sdm *DocumentMapping)
- func (dm *DocumentMapping) UnmarshalJSON(data []byte) error
- func (dm *DocumentMapping) Validate(cache *registry.Cache) error
- type FieldMapping
- type IndexMapping
- type IndexMappingImpl
- func (im *IndexMappingImpl) AddCustomAnalyzer(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddCustomCharFilter(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddCustomDateTimeParser(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddCustomTokenFilter(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddCustomTokenMap(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddCustomTokenizer(name string, config map[string]interface{}) error
- func (im *IndexMappingImpl) AddDocumentMapping(doctype string, dm *DocumentMapping)
- func (im *IndexMappingImpl) AnalyzeText(analyzerName string, text []byte) (analysis.TokenStream, error)
- func (im *IndexMappingImpl) AnalyzerNameForPath(path string) string
- func (im *IndexMappingImpl) AnalyzerNamed(name string) *analysis.Analyzer
- func (im *IndexMappingImpl) DateTimeParserNamed(name string) analysis.DateTimeParser
- func (im *IndexMappingImpl) DefaultSearchField() string
- func (im *IndexMappingImpl) FieldAnalyzer(field string) string
- func (im *IndexMappingImpl) MapDocument(doc *document.Document, data interface{}) error
- func (im *IndexMappingImpl) UnmarshalJSON(data []byte) error
- func (im *IndexMappingImpl) Validate() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( IndexDynamic = true StoreDynamic = true DocValuesDynamic = true // TODO revisit default? )
control the default behavior for dynamic fields (those not explicitly mapped)
var MappingJSONStrict = false
Functions ¶
Types ¶
type Classifier ¶
type Classifier interface {
Type() string
}
A Classifier is an interface describing any object which knows how to identify its own type. Alternatively, if a struct already has a Type field or method in conflict, one can use BleveType instead.
type DocumentMapping ¶
type DocumentMapping struct {
Enabled bool `json:"enabled"`
Dynamic bool `json:"dynamic"`
Properties map[string]*DocumentMapping `json:"properties,omitempty"`
Fields []*FieldMapping `json:"fields,omitempty"`
DefaultAnalyzer string `json:"default_analyzer"`
// StructTagKey overrides "json" when looking for field names in struct tags
StructTagKey string `json:"struct_tag_key,omitempty"`
}
A DocumentMapping describes how a type of document should be indexed. As documents can be hierarchical, named sub-sections of documents are mapped using the same structure in the Properties field. Each value inside a document can be indexed 0 or more ways. These index entries are called fields and are stored in the Fields field. Entire sections of a document can be ignored or excluded by setting Enabled to false. If not explicitly mapped, default mapping operations are used. To disable this automatic handling, set Dynamic to false.
func NewDocumentDisabledMapping ¶
func NewDocumentDisabledMapping() *DocumentMapping
NewDocumentDisabledMapping returns a new document mapping that will not perform any indexing.
func NewDocumentMapping ¶
func NewDocumentMapping() *DocumentMapping
NewDocumentMapping returns a new document mapping with all the default values.
func NewDocumentStaticMapping ¶
func NewDocumentStaticMapping() *DocumentMapping
NewDocumentStaticMapping returns a new document mapping that will not automatically index parts of a document without an explicit mapping.
func (*DocumentMapping) AddFieldMapping ¶
func (dm *DocumentMapping) AddFieldMapping(fm *FieldMapping)
AddFieldMapping adds the provided FieldMapping for this section of the document.
Example ¶
// you can only add field mapping to those properties which already have a document mapping
documentMapping := NewDocumentMapping()
subDocumentMapping := NewDocumentMapping()
documentMapping.AddSubDocumentMapping("Property", subDocumentMapping)
fieldMapping := NewTextFieldMapping()
fieldMapping.Analyzer = "en"
subDocumentMapping.AddFieldMapping(fieldMapping)
fmt.Println(len(documentMapping.Properties["Property"].Fields))
Output: 1
func (*DocumentMapping) AddFieldMappingsAt ¶
func (dm *DocumentMapping) AddFieldMappingsAt(property string, fms ...*FieldMapping)
AddFieldMappingsAt adds one or more FieldMappings at the named sub-document. If the named sub-document doesn't yet exist it is created for you. This is a convenience function to make most common mappings more concise. Otherwise, you would:
subMapping := NewDocumentMapping() subMapping.AddFieldMapping(fieldMapping) parentMapping.AddSubDocumentMapping(property, subMapping)
Example ¶
// you can only add field mapping to those properties which already have a document mapping
documentMapping := NewDocumentMapping()
subDocumentMapping := NewDocumentMapping()
documentMapping.AddSubDocumentMapping("NestedProperty", subDocumentMapping)
fieldMapping := NewTextFieldMapping()
fieldMapping.Analyzer = "en"
documentMapping.AddFieldMappingsAt("NestedProperty", fieldMapping)
fmt.Println(len(documentMapping.Properties["NestedProperty"].Fields))
Output: 1
func (*DocumentMapping) AddSubDocumentMapping ¶
func (dm *DocumentMapping) AddSubDocumentMapping(property string, sdm *DocumentMapping)
AddSubDocumentMapping adds the provided DocumentMapping as a sub-mapping for the specified named subsection.
Example ¶
// adds a document mapping for a property in a document
// useful for mapping nested documents
documentMapping := NewDocumentMapping()
subDocumentMapping := NewDocumentMapping()
documentMapping.AddSubDocumentMapping("Property", subDocumentMapping)
fmt.Println(len(documentMapping.Properties))
Output: 1
func (*DocumentMapping) UnmarshalJSON ¶
func (dm *DocumentMapping) UnmarshalJSON(data []byte) error
UnmarshalJSON offers custom unmarshaling with optional strict validation
type FieldMapping ¶
type FieldMapping struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
// Analyzer specifies the name of the analyzer to use for this field. If
// Analyzer is empty, traverse the DocumentMapping tree toward the root and
// pick the first non-empty DefaultAnalyzer found. If there is none, use
// the IndexMapping.DefaultAnalyzer.
Analyzer string `json:"analyzer,omitempty"`
// Store indicates whether to store field values in the index. Stored
// values can be retrieved from search results using SearchRequest.Fields.
Store bool `json:"store,omitempty"`
Index bool `json:"index,omitempty"`
// IncludeTermVectors, if true, makes terms occurrences to be recorded for
// this field. It includes the term position within the terms sequence and
// the term offsets in the source document field. Term vectors are required
// to perform phrase queries or terms highlighting in source documents.
IncludeTermVectors bool `json:"include_term_vectors,omitempty"`
IncludeInAll bool `json:"include_in_all,omitempty"`
DateFormat string `json:"date_format,omitempty"`
// DocValues, if true makes the index uninverting possible for this field
// It is useful for faceting and sorting queries.
DocValues bool `json:"docvalues,omitempty"`
}
A FieldMapping describes how a specific item should be put into the index.
func NewBooleanFieldMapping ¶
func NewBooleanFieldMapping() *FieldMapping
NewBooleanFieldMapping returns a default field mapping for booleans
func NewDateTimeFieldMapping ¶
func NewDateTimeFieldMapping() *