@@ -66,6 +66,9 @@ public class TermsLookup implements Writeable, ToXContentFragment {
66
66
private String routing ;
67
67
private QueryBuilder query ;
68
68
69
+ public TermsLookup (String index , String id , String path ) {
70
+ this (index , id , path , null ); // Delegate to the existing constructor
71
+ }
69
72
public TermsLookup (String index , String id , String path , QueryBuilder query ) {
70
73
if (Strings .isEmpty (index )) {
71
74
throw new IllegalArgumentException ("index cannot be null or empty for TermsLookup" );
@@ -108,8 +111,10 @@ public TermsLookup(StreamInput in) throws IOException {
108
111
if (in .getVersion ().onOrAfter (Version .V_2_17_0 )) {
109
112
store = in .readBoolean ();
110
113
}
111
- if (in .readBoolean ()) {
112
- query = in .readOptionalWriteable (inStream -> inStream .readNamedWriteable (QueryBuilder .class ));
114
+ if (in .getVersion ().onOrAfter (Version .V_3_0_0 )) {
115
+ if (in .readBoolean ()) {
116
+ query = in .readOptionalWriteable (inStream -> inStream .readNamedWriteable (QueryBuilder .class ));
117
+ }
113
118
}
114
119
}
115
120
@@ -125,12 +130,7 @@ public void writeTo(StreamOutput out) throws IOException {
125
130
if (out .getVersion ().onOrAfter (Version .V_2_17_0 )) {
126
131
out .writeBoolean (store );
127
132
}
128
- if (query != null ) {
129
- out .writeBoolean (true );
130
- out .writeOptionalWriteable (query );
131
- } else {
132
- out .writeBoolean (false );
133
- }
133
+ out .writeOptionalWriteable (query );
134
134
}
135
135
136
136
public String path () {
@@ -181,18 +181,10 @@ public TermsLookup id(String id) {
181
181
String path = (String ) args [2 ];
182
182
QueryBuilder query = (QueryBuilder ) args [3 ]; // Optional query
183
183
184
- // Ensure either `id` or `query` is provided, but not both
185
- if (id == null && query == null ) {
186
- throw new IllegalArgumentException ("[" + TermsQueryBuilder .NAME + "] query lookup element requires specifying either the id or the query." );
187
- }
188
- if (id != null && query != null ) {
189
- throw new IllegalArgumentException ("[" + TermsQueryBuilder .NAME + "] query lookup element cannot specify both id and query." );
190
- }
191
184
return new TermsLookup (index , id , path , query );
192
185
});
193
186
static {
194
187
PARSER .declareString (constructorArg (), new ParseField ("index" )); // Required
195
- //PARSER.declareString(constructorArg(), new ParseField("id")); // Optional
196
188
PARSER .declareString (optionalConstructorArg (), new ParseField ("id" )); // Optional
197
189
PARSER .declareString (constructorArg (), new ParseField ("path" )); // Required
198
190
PARSER .declareObject (optionalConstructorArg (), (parser , context ) -> {
0 commit comments