|
23 | 23 | import org.elasticsearch.action.search.SearchType;
|
24 | 24 | import org.elasticsearch.search.sort.SortOrder;
|
25 | 25 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
| 26 | +import org.hamcrest.CoreMatchers; |
26 | 27 | import org.junit.After;
|
27 | 28 | import org.junit.Test;
|
28 | 29 |
|
29 | 30 | import java.util.Arrays;
|
30 | 31 | import java.util.List;
|
31 | 32 | import java.util.Map;
|
32 | 33 |
|
33 |
| -import static org.elasticsearch.client.Requests.*; |
| 34 | +import static org.elasticsearch.client.Requests.searchRequest; |
34 | 35 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
35 | 36 | import static org.elasticsearch.index.query.FilterBuilders.scriptFilter;
|
36 | 37 | import static org.elasticsearch.index.query.QueryBuilders.*;
|
37 | 38 | import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
| 39 | +import static org.hamcrest.CoreMatchers.is; |
38 | 40 | import static org.hamcrest.Matchers.equalTo;
|
39 | 41 |
|
40 | 42 | /**
|
@@ -205,4 +207,26 @@ public void testCustomScriptBoost() throws Exception {
|
205 | 207 | logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
206 | 208 | logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
207 | 209 | }
|
| 210 | + |
| 211 | + /** |
| 212 | + * Test case for #4: https://github.com/elasticsearch/elasticsearch-lang-python/issues/4 |
| 213 | + * Update request that uses python script with no parameters fails with NullPointerException |
| 214 | + * @throws Exception |
| 215 | + */ |
| 216 | + @Test |
| 217 | + public void testPythonEmptyParameters() throws Exception { |
| 218 | + wipeIndices("test"); |
| 219 | + createIndex("test"); |
| 220 | + index("test", "type1", "1", jsonBuilder().startObject().field("myfield", "foo").endObject()); |
| 221 | + refresh(); |
| 222 | + |
| 223 | + client().prepareUpdate("test", "type1", "1").setScriptLang("python").setScript("ctx[\"_source\"][\"myfield\"]=\"bar\"") |
| 224 | + .execute().actionGet(); |
| 225 | + refresh(); |
| 226 | + |
| 227 | + Object value = get("test", "type1", "1").getSourceAsMap().get("myfield"); |
| 228 | + assertThat(value instanceof String, is(true)); |
| 229 | + |
| 230 | + assertThat((String) value, CoreMatchers.equalTo("bar")); |
| 231 | + } |
208 | 232 | }
|
0 commit comments