mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 01:19:02 +00:00
Update request that uses python script with no parameters fails with NullPointerException
Closes #4.
This commit is contained in:
parent
c065e3884b
commit
3fc121f603
@ -107,8 +107,10 @@ public class PythonScriptEngineService extends AbstractComponent implements Scri
|
||||
public PythonExecutableScript(PyCode code, Map<String, Object> vars) {
|
||||
this.code = code;
|
||||
this.pyVars = new PyStringMap();
|
||||
for (Map.Entry<String, Object> entry : vars.entrySet()) {
|
||||
pyVars.__setitem__(entry.getKey(), Py.java2py(entry.getValue()));
|
||||
if (vars != null) {
|
||||
for (Map.Entry<String, Object> entry : vars.entrySet()) {
|
||||
pyVars.__setitem__(entry.getKey(), Py.java2py(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -30,11 +31,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.client.Requests.*;
|
||||
import static org.elasticsearch.client.Requests.searchRequest;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.FilterBuilders.scriptFilter;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
@ -205,4 +207,26 @@ public class PythonScriptSearchTests extends ElasticsearchIntegrationTest {
|
||||
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for #4: https://github.com/elasticsearch/elasticsearch-lang-python/issues/4
|
||||
* Update request that uses python script with no parameters fails with NullPointerException
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testPythonEmptyParameters() throws Exception {
|
||||
wipeIndices("test");
|
||||
createIndex("test");
|
||||
index("test", "type1", "1", jsonBuilder().startObject().field("myfield", "foo").endObject());
|
||||
refresh();
|
||||
|
||||
client().prepareUpdate("test", "type1", "1").setScriptLang("python").setScript("ctx[\"_source\"][\"myfield\"]=\"bar\"")
|
||||
.execute().actionGet();
|
||||
refresh();
|
||||
|
||||
Object value = get("test", "type1", "1").getSourceAsMap().get("myfield");
|
||||
assertThat(value instanceof String, is(true));
|
||||
|
||||
assertThat((String) value, CoreMatchers.equalTo("bar"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user