|
10 | 10 | import org.elasticsearch.action.index.IndexRequest; |
11 | 11 | import org.elasticsearch.action.support.WriteRequest; |
12 | 12 | import org.elasticsearch.common.settings.Settings; |
| 13 | +import org.elasticsearch.common.util.CollectionUtils; |
| 14 | +import org.elasticsearch.plugins.Plugin; |
13 | 15 | import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; |
| 16 | +import org.elasticsearch.xpack.kql.KqlPlugin; |
14 | 17 | import org.junit.Before; |
15 | 18 | import org.junit.Ignore; |
16 | 19 |
|
| 20 | +import java.util.Collection; |
17 | 21 | import java.util.List; |
18 | 22 |
|
19 | 23 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
@@ -99,6 +103,109 @@ public void testScorePlusWhereMatch() { |
99 | 103 | } |
100 | 104 | } |
101 | 105 |
|
| 106 | + public void testScorePlusWhereKql() { |
| 107 | + var query = """ |
| 108 | + FROM test METADATA _score |
| 109 | + | WHERE kql("brown") |
| 110 | + | WHERE match(content, "fox") |
| 111 | + | EVAL first_score = score(kql("brown")) |
| 112 | + | KEEP id, _score, first_score |
| 113 | + | SORT id |
| 114 | + """; |
| 115 | + |
| 116 | + try (var resp = run(query)) { |
| 117 | + assertColumnNames(resp.columns(), List.of("id", "_score", "first_score")); |
| 118 | + assertColumnTypes(resp.columns(), List.of("integer", "double", "double")); |
| 119 | + assertValues( |
| 120 | + resp.values(), |
| 121 | + List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587)) |
| 122 | + ); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + public void testScorePlusWhereQstr() { |
| 127 | + var query = """ |
| 128 | + FROM test METADATA _score |
| 129 | + | WHERE qstr("brown") |
| 130 | + | WHERE match(content, "fox") |
| 131 | + | EVAL first_score = score(qstr("brown")) |
| 132 | + | KEEP id, _score, first_score |
| 133 | + | SORT id |
| 134 | + """; |
| 135 | + |
| 136 | + try (var resp = run(query)) { |
| 137 | + assertColumnNames(resp.columns(), List.of("id", "_score", "first_score")); |
| 138 | + assertColumnTypes(resp.columns(), List.of("integer", "double", "double")); |
| 139 | + assertValues( |
| 140 | + resp.values(), |
| 141 | + List.of(List.of(1, 1.4274532794952393, 0.2708943784236908), List.of(6, 1.1248724460601807, 0.21347221732139587)) |
| 142 | + ); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + public void testScorePlusWhereQstrAndMatch() { |
| 147 | + var query = """ |
| 148 | + FROM test METADATA _score |
| 149 | + | WHERE qstr("brown") AND match(content, "fox") |
| 150 | + | EVAL first_score = score(qstr("brown") AND match(content, "fox")) |
| 151 | + | KEEP id, _score, first_score |
| 152 | + | SORT id |
| 153 | + """; |
| 154 | + |
| 155 | + try (var resp = run(query)) { |
| 156 | + assertColumnNames(resp.columns(), List.of("id", "_score", "first_score")); |
| 157 | + assertColumnTypes(resp.columns(), List.of("integer", "double", "double")); |
| 158 | + assertValues( |
| 159 | + resp.values(), |
| 160 | + List.of(List.of(1, 1.4274532794952393, 1.4274532496929169), List.of(6, 1.1248724460601807, 1.1248724162578583)) |
| 161 | + ); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + public void testScorePlusWhereKqlAndMatch() { |
| 166 | + var query = """ |
| 167 | + FROM test METADATA _score |
| 168 | + | WHERE kql("brown") AND match(content, "fox") |
| 169 | + | EVAL first_score = score(kql("brown") AND match(content, "fox")) |
| 170 | + | KEEP id, _score, first_score |
| 171 | + | SORT id |
| 172 | + """; |
| 173 | + |
| 174 | + try (var resp = run(query)) { |
| 175 | + assertColumnNames(resp.columns(), List.of("id", "_score", "first_score")); |
| 176 | + assertColumnTypes(resp.columns(), List.of("integer", "double", "double")); |
| 177 | + assertValues( |
| 178 | + resp.values(), |
| 179 | + List.of(List.of(1, 1.4274532794952393, 1.4274532496929169), List.of(6, 1.1248724460601807, 1.1248724162578583)) |
| 180 | + ); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + public void testScorePlusWhereQstrORMatch() { |
| 185 | + var query = """ |
| 186 | + FROM test METADATA _score |
| 187 | + | WHERE qstr("brown") OR match(content, "fox") |
| 188 | + | EVAL first_score = score(qstr("brown") OR match(content, "fox")) |
| 189 | + | KEEP id, _score, first_score |
| 190 | + | SORT id |
| 191 | + """; |
| 192 | + |
| 193 | + try (var resp = run(query)) { |
| 194 | + assertColumnNames(resp.columns(), List.of("id", "_score", "first_score")); |
| 195 | + assertColumnTypes(resp.columns(), List.of("integer", "double", "double")); |
| 196 | + assertValues( |
| 197 | + resp.values(), |
| 198 | + List.of( |
| 199 | + List.of(1, 1.4274532794952393, 1.4274532496929169), |
| 200 | + List.of(2, 0.2708943784236908, 0.2708943784236908), |
| 201 | + List.of(3, 0.2708943784236908, 0.2708943784236908), |
| 202 | + List.of(4, 0.19301524758338928, 0.19301524758338928), |
| 203 | + List.of(6, 1.1248724460601807, 1.1248724162578583) |
| 204 | + ) |
| 205 | + ); |
| 206 | + } |
| 207 | + } |
| 208 | + |
102 | 209 | public void testSimpleScoreAlone() { |
103 | 210 | var query = """ |
104 | 211 | FROM test METADATA _score |
@@ -142,4 +249,9 @@ private void createAndPopulateIndex() { |
142 | 249 | .get(); |
143 | 250 | ensureYellow(indexName); |
144 | 251 | } |
| 252 | + |
| 253 | + @Override |
| 254 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 255 | + return CollectionUtils.appendToCopy(super.nodePlugins(), KqlPlugin.class); |
| 256 | + } |
145 | 257 | } |
0 commit comments