13
13
import org .elasticsearch .client .Request ;
14
14
import org .elasticsearch .client .Response ;
15
15
import org .elasticsearch .client .ResponseException ;
16
+ import org .elasticsearch .common .collect .Iterators ;
16
17
import org .elasticsearch .test .ListMatcher ;
17
18
import org .elasticsearch .test .MapMatcher ;
18
19
import org .elasticsearch .test .TestClustersThreadFilter ;
21
22
import org .elasticsearch .xcontent .XContentType ;
22
23
import org .elasticsearch .xpack .esql .AssertWarnings ;
23
24
import org .elasticsearch .xpack .esql .qa .rest .RestEsqlTestCase ;
25
+ import org .hamcrest .Matcher ;
24
26
import org .junit .ClassRule ;
25
27
26
28
import java .io .IOException ;
39
41
import static org .elasticsearch .xpack .esql .qa .rest .RestEsqlTestCase .runEsql ;
40
42
import static org .elasticsearch .xpack .esql .qa .single_node .RestEsqlIT .commonProfile ;
41
43
import static org .elasticsearch .xpack .esql .qa .single_node .RestEsqlIT .fixTypesOnProfile ;
44
+ import static org .hamcrest .Matchers .anyOf ;
42
45
import static org .hamcrest .Matchers .equalTo ;
43
46
import static org .hamcrest .Matchers .instanceOf ;
44
47
import static org .hamcrest .Matchers .startsWith ;
@@ -79,7 +82,7 @@ public void testEquality() throws IOException {
79
82
case "match_only_text" , "semantic_text" -> true ;
80
83
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
81
84
};
82
- testPushQuery (value , esqlQuery , luceneQuery , filterInCompute , true );
85
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , filterInCompute , true );
83
86
}
84
87
85
88
public void testEqualityTooBigToPush () throws IOException {
@@ -93,7 +96,7 @@ public void testEqualityTooBigToPush() throws IOException {
93
96
case "semantic_text" -> "FieldExistsQuery [field=_primary_term]" ;
94
97
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
95
98
};
96
- testPushQuery (value , esqlQuery , luceneQuery , true , true );
99
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , true , true );
97
100
}
98
101
99
102
/**
@@ -111,7 +114,7 @@ public void testEqualityOrTooBig() throws IOException {
111
114
case "semantic_text" -> "FieldExistsQuery [field=_primary_term]" ;
112
115
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
113
116
};
114
- testPushQuery (value , esqlQuery , luceneQuery , true , true );
117
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , true , true );
115
118
}
116
119
117
120
public void testEqualityOrOther () throws IOException {
@@ -131,7 +134,7 @@ public void testEqualityOrOther() throws IOException {
131
134
case "match_only_text" , "semantic_text" -> true ;
132
135
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
133
136
};
134
- testPushQuery (value , esqlQuery , luceneQuery , filterInCompute , true );
137
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , filterInCompute , true );
135
138
}
136
139
137
140
public void testEqualityAndOther () throws IOException {
@@ -140,23 +143,23 @@ public void testEqualityAndOther() throws IOException {
140
143
FROM test
141
144
| WHERE test == "%value" AND foo == 1
142
145
""" ;
143
- String luceneQuery = switch (type ) {
144
- case "text" , "auto" -> "#test.keyword:%value -_ignored:test.keyword #foo:[1 TO 1]" ;
145
- case "match_only_text" -> "foo:[1 TO 1]" ;
146
+ List < String > luceneQueryOptions = switch (type ) {
147
+ case "text" , "auto" -> List . of ( "#test.keyword:%value -_ignored:test.keyword #foo:[1 TO 1]" ) ;
148
+ case "match_only_text" -> List . of ( "foo:[1 TO 1]" ) ;
146
149
case "semantic_text" ->
147
150
/*
148
151
* single_value_match is here because there are extra documents hiding in the index
149
152
* that don't have the `foo` field.
150
153
*/
151
- "#foo:[1 TO 1] #single_value_match(foo)" ;
154
+ List . of ( "#foo:[1 TO 1] #single_value_match(foo)" , "foo:[1 TO 1]" ) ;
152
155
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
153
156
};
154
157
boolean filterInCompute = switch (type ) {
155
158
case "text" , "auto" -> false ;
156
159
case "match_only_text" , "semantic_text" -> true ;
157
160
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
158
161
};
159
- testPushQuery (value , esqlQuery , luceneQuery , filterInCompute , true );
162
+ testPushQuery (value , esqlQuery , luceneQueryOptions , filterInCompute , true );
160
163
}
161
164
162
165
public void testInequality () throws IOException {
@@ -171,7 +174,7 @@ public void testInequality() throws IOException {
171
174
case "semantic_text" -> "FieldExistsQuery [field=_primary_term]" ;
172
175
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
173
176
};
174
- testPushQuery (value , esqlQuery , luceneQuery , true , true );
177
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , true , true );
175
178
}
176
179
177
180
public void testInequalityTooBigToPush () throws IOException {
@@ -185,7 +188,7 @@ public void testInequalityTooBigToPush() throws IOException {
185
188
case "semantic_text" -> "FieldExistsQuery [field=_primary_term]" ;
186
189
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
187
190
};
188
- testPushQuery (value , esqlQuery , luceneQuery , true , false );
191
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , true , false );
189
192
}
190
193
191
194
public void testCaseInsensitiveEquality () throws IOException {
@@ -199,10 +202,10 @@ public void testCaseInsensitiveEquality() throws IOException {
199
202
case "semantic_text" -> "FieldExistsQuery [field=_primary_term]" ;
200
203
default -> throw new UnsupportedOperationException ("unknown type [" + type + "]" );
201
204
};
202
- testPushQuery (value , esqlQuery , luceneQuery , true , true );
205
+ testPushQuery (value , esqlQuery , List . of ( luceneQuery ) , true , true );
203
206
}
204
207
205
- private void testPushQuery (String value , String esqlQuery , String luceneQuery , boolean filterInCompute , boolean found )
208
+ private void testPushQuery (String value , String esqlQuery , List < String > luceneQueryOptions , boolean filterInCompute , boolean found )
206
209
throws IOException {
207
210
indexValue (value );
208
211
String differentValue = randomValueOtherThan (value , () -> randomAlphaOfLength (value .isEmpty () ? 1 : value .length ()));
@@ -222,6 +225,12 @@ private void testPushQuery(String value, String esqlQuery, String luceneQuery, b
222
225
matchesList ().item (matchesMap ().entry ("name" , "test" ).entry ("type" , "text" )),
223
226
equalTo (found ? List .of (List .of (value )) : List .of ())
224
227
);
228
+ Matcher <String > luceneQueryMatcher = anyOf (
229
+ () -> Iterators .map (
230
+ luceneQueryOptions .iterator (),
231
+ (String s ) -> equalTo (s .replaceAll ("%value" , value ).replaceAll ("%different_value" , differentValue ))
232
+ )
233
+ );
225
234
226
235
@ SuppressWarnings ("unchecked" )
227
236
List <Map <String , Object >> profiles = (List <Map <String , Object >>) ((Map <String , Object >) result .get ("profile" )).get ("drivers" );
@@ -232,7 +241,7 @@ private void testPushQuery(String value, String esqlQuery, String luceneQuery, b
232
241
@ SuppressWarnings ("unchecked" )
233
242
List <Map <String , Object >> operators = (List <Map <String , Object >>) p .get ("operators" );
234
243
for (Map <String , Object > o : operators ) {
235
- sig .add (checkOperatorProfile (o , luceneQuery . replaceAll ( "%value" , value ). replaceAll ( "%different_value" , differentValue ) ));
244
+ sig .add (checkOperatorProfile (o , luceneQueryMatcher ));
236
245
}
237
246
String description = p .get ("description" ).toString ();
238
247
switch (description ) {
@@ -317,7 +326,7 @@ private void indexValue(String value) throws IOException {
317
326
318
327
private static final Pattern TO_NAME = Pattern .compile ("\\ [.+" , Pattern .DOTALL );
319
328
320
- private static String checkOperatorProfile (Map <String , Object > o , String query ) {
329
+ private static String checkOperatorProfile (Map <String , Object > o , Matcher < String > query ) {
321
330
String name = (String ) o .get ("operator" );
322
331
name = TO_NAME .matcher (name ).replaceAll ("" );
323
332
if (name .equals ("LuceneSourceOperator" )) {
0 commit comments