Proper syntax of script fields


I was trying to use scripted fields as described in the docs for the ultimate goal of using them in Kibana but I was unable to get them to work via curl. I tried adapting the query shown in the docs for my own setup/example but I was unable to get it to work as my response did not contain '_source' or 'doc'. I have source enabled and I did not disable doc values in my mapping.

I was wondering if someone could shed some light into getting script fields working.

Thanks in advance!


Could you please share a sample of your doc and query with scripted fields? That would help to spot a syntax issue or whatever.


thanks for the quick response!

If I do something such as:
curl -XGET 'localhost:9200/dns2/_search?pretty' -d' { "query" : { "match_all": {} }}'

I get a response without _source or doc values.

I changed the query from the one on the documentation (to perform the search on an index) because if I did not do that, I would only get a response that includes the .kibana indices.
Query: curl -XGET 'localhost:9200/dns2/_search?pretty' -d' { "query" : { "match_all": {} }}'


I have an integer field called 'domain_name_length' so I suppose I can use the full example from the documentation but instead of 'my_field_name', I'll use 'domain_name_length'. Therefore, my query would be as follows:

curl -XGET 'localhost:9200/dns2/_search?pretty' -d '{
	"query": {
		"match_all": {}
	"script_fields": {
		"test1": {
			"script": {
				"lang": "painless",
				"inline": "doc['domain_name_length'].value * 2"
		"test2": {
			"script": {
				"lang": "painless",
				"inline": "doc['domain_name_length'].value * factor",
				"params": {
					"factor": 2.0

My response gives me an error as it does not contain doc values.

It looks like the ' in the scripted field doc['domain_name_length'] must be correctly escaped when used with the curl tool, because curl also uses the ' as a delimiter for the request body.

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