/
store_param.go
52 lines (46 loc) · 1.64 KB
/
store_param.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package picker
import "github.com/chanced/dynamic"
const DefaultStore = false
// WithStore is a mapping with a store paramter.
//
// By default, field values are indexed to make them searchable, but they are
// not stored. This means that the field can be queried, but the original field
// value cannot be retrieved.
//
// Usually this doesn’t matter. The field value is already part of the _source
// field, which is stored by default. If you only want to retrieve the value of
// a single field or of a few fields, instead of the whole _source, then this
// can be achieved with source filtering.
//
// In certain situations it can make sense to store a field. For instance, if
// you have a document with a title, a date, and a very large content field, you
// may want to retrieve just the title and the date without having to extract
// those fields from a large _source field
//
// Stored fields returned as arrays
//
// For consistency, stored fields are always returned as an array because there
// is no way of knowing if the original field value was a single value, multiple
// values, or an empty array.
//
// The original value can be retrieved from the _source field instead.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-store.html
type WithStore interface {
Store() bool
SetStore(v interface{}) error
}
type storeParam struct {
store dynamic.Bool
}
// Store returns the StoreAttr Value or false
func (sa storeParam) Store() bool {
if v, ok := sa.store.Bool(); ok {
return v
}
return DefaultStore
}
// SetStore sets StoreAttr Value to v
func (sa *storeParam) SetStore(v interface{}) error {
return sa.store.Set(v)
}