-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensearchutil.go
87 lines (78 loc) · 3.81 KB
/
opensearchutil.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package opensearchutil
import (
_ "embed"
)
const (
DefaultMaxDepth = 10
tagKey = "opensearch"
tagOptionType = "type"
tagOptionFormat = "format"
tagOptionAnalyzer = "analyzer"
tagOptionIndexPrefixes = "index_prefixes"
)
// MappingProperty corresponds to mappings.properties of a mapping JSON.
// MappingProperty defines either a primitive data type, in which case FieldType != "", or an object, in which case
// len(Children) > 0.
type MappingProperty struct {
FieldName string
FieldType string
FieldFormat *string
Analyzer *string
IndexPrefixes *map[string]string
Children []MappingProperty
}
// IndexSettings allows to specify settings of an index, at its creation. This struct includes both static (those
// that are specified at index increation) settings, and dynamic settings (those that can be altered after index
// creation).
// Refer to https://opensearch.org/docs/latest/api-reference/index-apis/create-index/ for docs on each setting.
type IndexSettings struct {
NumberOfShards *uint16 `json:"number_of_shards,omitempty"`
NumberOfRoutingShards *uint16 `json:"number_of_routing_shards,omitempty"`
ShardCheckOnStartup *bool `json:"shard.check_on_startup,omitempty"`
Codec *string `json:"codec,omitempty"`
RoutingPartitionSize *uint16 `json:"routing_partition_size,omitempty"`
SoftDeletesRetentionLeasePeriod *string `json:"soft_deletes.retention_lease.period,omitempty"`
LoadFixedBitsetFiltersEagerly *bool `json:"load_fixed_bitset_filters_eagerly,omitempty"`
Hidden *bool `json:"hidden,omitempty"`
NumberOfReplicas *uint16 `json:"number_of_replicas,omitempty"`
AutoExpandReplicas *string `json:"auto_expand_replicas,omitempty"`
SearchIdleAfter *string `json:"search.idle.after,omitempty"`
RefreshInterval *string `json:"refresh_interval,omitempty"`
MaxResultWindow *uint64 `json:"max_result_window,omitempty"`
MaxInnerResultWindow *uint64 `json:"max_inner_result_window,omitempty"`
MaxRescoreWindow *uint64 `json:"max_rescore_window,omitempty"`
MaxDocvalueFieldsSearch *uint64 `json:"max_docvalue_fields_search,omitempty"`
MaxScriptFields *uint16 `json:"max_script_fields,omitempty"`
MaxNgramDiff *uint16 `json:"max_ngram_diff,omitempty"`
MaxShingleDiff *uint16 `json:"max_shingle_diff,omitempty"`
MaxRefreshListeners *uint16 `json:"max_refresh_listeners,omitempty"`
AnalyzeMaxTokenCount *uint16 `json:"analyze.max_token_count,omitempty"`
HighlightMaxAnalyzedOffset *uint64 `json:"highlight.max_analyzed_offset,omitempty"`
MaxTermsCount *uint64 `json:"max_terms_count,omitempty"`
MaxRegexLength *uint16 `json:"max_regex_length,omitempty"`
QueryDefaultField *string `json:"query.default_field,omitempty"`
RoutingAllocationEnable *string `json:"routing.allocation_enable,omitempty"`
RoutingRebalanceEnable *string `json:"routing.rebalance_enable,omitempty"`
GcDeletes *string `json:"gc_deletes,omitempty"`
DefaultPipeline *string `json:"default_pipeline,omitempty"`
FinalPipeline *string `json:"final_pipeline,omitempty"`
}
type JsonFormatter interface {
FormatJson(str []byte) ([]byte, error)
}
type FieldNameTransformer interface {
TransformFieldName(name string) (string, error)
}
func (p MappingProperty) GetDepth() int {
return getDepth(p)
}
func getDepth(property MappingProperty) int {
depth := 1
for _, child := range property.Children {
childDepth := getDepth(child) + 1
if childDepth > depth {
depth = childDepth
}
}
return depth
}