Sandbox for painless?

(Abdelkarim Mateos) #1

Is there any site or method to make sandbox with Painless?
Can I test the scripts as if it were the javascript language?

How can I test my scripts?

For example in some functions I wondered if the value is correct.

boolean isCategory(def proposal, def matching) {
	int length = String.valueOf(1000).length();
    // I like test value of length with echo o sandbox os smilar
    // Some code
	return true 

(Nik Everett) #2

The best way to test your scripts is by running them against a local instance of Elasticsearch.

Painless doesn't have a REPL or online sandbox or anything, partly because context is so important to the scripts and partly because we haven't built one. By context I mean that a script that works in an update may not work in filter query or a script field. They have very different things available to them.

OTOH examples like your function would run fine in an "empty" context. This falls more into the category of "we haven't built it". And we may never build it because of the context issue.

And, no you can't really write javascript and expect it to work in painless. Painless is kind of like Java and kind of like Groovy in syntax. Lots of groovy is valid painless. Most painless is valid groovy.

I think the simplest way to test painless is with an index with a single document, a search that matches all documents, and a script field. The script field lets you return a value and you can see it in the results.

(Abdelkarim Mateos) #3


After read your reply, I search for any solutions.

Perfect for test too many pieces of code such example on post.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.