Merge pull request #139 from sacheendra/examples
adds examples for mapping functions and special field * in docs
This commit is contained in:
commit
0356479e85
|
@ -77,6 +77,8 @@ func ExampleIndex_indexing() {
|
|||
// 2
|
||||
}
|
||||
|
||||
// Examples for query related functions
|
||||
|
||||
func ExampleNewMatchQuery() {
|
||||
// finds documents with fields fully matching the given query text
|
||||
query := NewMatchQuery("named one")
|
||||
|
@ -434,3 +436,47 @@ func ExampleNewDisjunctionQueryMin() {
|
|||
// Output:
|
||||
// 0
|
||||
}
|
||||
|
||||
// Examples for Mapping related functions
|
||||
|
||||
func ExampleDocumentMapping_AddSubDocumentMapping() {
|
||||
// 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 ExampleDocumentMapping_AddFieldMapping() {
|
||||
// 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 ExampleDocumentMapping_AddFieldMappingsAt() {
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -156,6 +156,8 @@ func (h *HighlightRequest) AddField(field string) {
|
|||
// Facets describe the set of facets to be computed.
|
||||
// Explain triggers inclusion of additional search
|
||||
// result score explanations.
|
||||
//
|
||||
// A special field named "*" can be used to return all fields.
|
||||
type SearchRequest struct {
|
||||
Query Query `json:"query"`
|
||||
Size int `json:"size"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user