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
|
// 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Examples for query related functions
|
||||||
|
|
||||||
func ExampleNewMatchQuery() {
|
func ExampleNewMatchQuery() {
|
||||||
// finds documents with fields fully matching the given query text
|
// finds documents with fields fully matching the given query text
|
||||||
query := NewMatchQuery("named one")
|
query := NewMatchQuery("named one")
|
||||||
@ -434,3 +436,47 @@ func ExampleNewDisjunctionQueryMin() {
|
|||||||
// Output:
|
// Output:
|
||||||
// 0
|
// 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.
|
// Facets describe the set of facets to be computed.
|
||||||
// Explain triggers inclusion of additional search
|
// Explain triggers inclusion of additional search
|
||||||
// result score explanations.
|
// result score explanations.
|
||||||
|
//
|
||||||
|
// A special field named "*" can be used to return all fields.
|
||||||
type SearchRequest struct {
|
type SearchRequest struct {
|
||||||
Query Query `json:"query"`
|
Query Query `json:"query"`
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
|
Loading…
Reference in New Issue
Block a user