|
20 | 20 | package org.elasticsearch.search.aggregations.metrics;
|
21 | 21 |
|
22 | 22 | import org.elasticsearch.action.index.IndexRequestBuilder;
|
| 23 | +import org.elasticsearch.action.search.SearchPhaseExecutionException; |
| 24 | +import org.elasticsearch.action.search.SearchRequestBuilder; |
23 | 25 | import org.elasticsearch.action.search.SearchResponse;
|
24 | 26 | import org.elasticsearch.common.bytes.BytesArray;
|
25 | 27 | import org.elasticsearch.common.settings.Settings;
|
|
62 | 64 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
63 | 65 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
|
64 | 66 | import static org.hamcrest.Matchers.allOf;
|
| 67 | +import static org.hamcrest.Matchers.containsString; |
65 | 68 | import static org.hamcrest.Matchers.equalTo;
|
66 | 69 | import static org.hamcrest.Matchers.greaterThan;
|
67 | 70 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
@@ -322,11 +325,11 @@ public void testMap() {
|
322 | 325 | assertThat(numShardsRun, greaterThan(0));
|
323 | 326 | }
|
324 | 327 |
|
325 |
| - public void testMapWithParams() { |
| 328 | + public void testExplicitAggParam() { |
326 | 329 | Map<String, Object> params = new HashMap<>();
|
327 | 330 | params.put("_agg", new ArrayList<>());
|
328 | 331 |
|
329 |
| - Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", params); |
| 332 | + Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", Collections.emptyMap()); |
330 | 333 |
|
331 | 334 | SearchResponse response = client().prepareSearch("idx")
|
332 | 335 | .setQuery(matchAllQuery())
|
@@ -1001,4 +1004,16 @@ public void testDontCacheScripts() throws Exception {
|
1001 | 1004 | assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
|
1002 | 1005 | .getMissCount(), equalTo(0L));
|
1003 | 1006 | }
|
| 1007 | + |
| 1008 | + public void testConflictingAggAndScriptParams() { |
| 1009 | + Map<String, Object> params = Collections.singletonMap("param1", "12"); |
| 1010 | + Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_agg.add(1)", params); |
| 1011 | + |
| 1012 | + SearchRequestBuilder builder = client().prepareSearch("idx") |
| 1013 | + .setQuery(matchAllQuery()) |
| 1014 | + .addAggregation(scriptedMetric("scripted").params(params).mapScript(mapScript)); |
| 1015 | + |
| 1016 | + SearchPhaseExecutionException ex = expectThrows(SearchPhaseExecutionException.class, builder::get); |
| 1017 | + assertThat(ex.getCause().getMessage(), containsString("Parameter name \"param1\" used in both aggregation and script parameters")); |
| 1018 | + } |
1004 | 1019 | }
|
0 commit comments