@@ -32,42 +32,43 @@ import { GeoHash, GeoHashPrecision, GeoLocation } from '@_types/Geo'
32
32
import { double , float , integer , long } from '@_types/Numeric'
33
33
import { AdditionalProperties } from '@spec_utils/behaviors'
34
34
35
- export class Suggest < T > {
35
+ /**
36
+ * @variants external
37
+ */
38
+ export type Suggest < TDocument > =
39
+ | CompletionSuggest < TDocument >
40
+ | PhraseSuggest
41
+ | TermSuggest
42
+
43
+ export class SuggestBase {
36
44
length : integer
37
45
offset : integer
38
- options : SuggestOption < T > [ ]
39
46
text : string
40
47
}
41
48
42
- export class Suggester implements AdditionalProperties < string , FieldSuggester > {
43
- /** Global suggest text, to avoid repetition when the same text is used in several suggesters */
44
- text ?: string
49
+ /**
50
+ * @variant name=completion
51
+ */
52
+ export class CompletionSuggest < TDocument > extends SuggestBase {
53
+ options : CompletionSuggestOption < TDocument > [ ]
45
54
}
46
55
47
56
/**
48
- * @variants container
57
+ * @variant name=phrase
49
58
*/
50
- export class FieldSuggester {
51
- completion ?: CompletionSuggester
52
- phrase ?: PhraseSuggester
53
- prefix ?: string
54
- regex ?: string
55
- term ?: TermSuggester
56
- text ?: string
59
+ export class PhraseSuggest extends SuggestBase {
60
+ options : PhraseSuggestOption
57
61
}
58
62
59
- export class SuggesterBase {
60
- field : Field
61
- analyzer ?: string
62
- size ?: integer
63
+ /**
64
+ * @variant name=term
65
+ */
66
+ export class TermSuggest extends SuggestBase {
67
+ options : TermSuggestOption
63
68
}
64
69
65
- /** @codegen_names completion, phrase, term */
66
- export type SuggestOption < TDocument > =
67
- | CompletionSuggestOption < TDocument >
68
- | PhraseSuggestOption
69
- | TermSuggestOption
70
-
70
+ // In the ES code a nested Hit object is expanded inline. Not all Hit fields have been
71
+ // added below as many do not make sense in the context of a suggestion.
71
72
export class CompletionSuggestOption < TDocument > {
72
73
collate_match ?: boolean
73
74
contexts ?: Dictionary < string , Context [ ] >
@@ -76,8 +77,8 @@ export class CompletionSuggestOption<TDocument> {
76
77
_index : IndexName
77
78
_type ?: Type
78
79
_routing ?: Routing
79
- _score : double
80
- _source : TDocument
80
+ _score ? : double
81
+ _source ? : TDocument
81
82
text : string
82
83
}
83
84
@@ -89,10 +90,33 @@ export class PhraseSuggestOption {
89
90
90
91
export class TermSuggestOption {
91
92
text : string
92
- freq ? : long
93
+ freq : long
93
94
score : double
94
95
}
95
96
97
+ export class Suggester implements AdditionalProperties < string , FieldSuggester > {
98
+ /** Global suggest text, to avoid repetition when the same text is used in several suggesters */
99
+ text ?: string
100
+ }
101
+
102
+ /**
103
+ * @variants container
104
+ */
105
+ export class FieldSuggester {
106
+ completion ?: CompletionSuggester
107
+ phrase ?: PhraseSuggester
108
+ prefix ?: string
109
+ regex ?: string
110
+ term ?: TermSuggester
111
+ text ?: string
112
+ }
113
+
114
+ export class SuggesterBase {
115
+ field : Field
116
+ analyzer ?: string
117
+ size ?: integer
118
+ }
119
+
96
120
// completion suggester
97
121
98
122
export class CompletionSuggester extends SuggesterBase {
0 commit comments