Skip to content

Missing fields values unexpectedly return 0 in painless #29286

Closed
@mayya-sharipova

Description

@mayya-sharipova

Describe the feature: Missing fields values are not processed as expected in painless
Elasticsearch version (bin/elasticsearch --version): 6.2.3

Steps to reproduce:

PUT /indexscore1
{
  "mappings": {
			"doc": {
				"properties": {
					"f1": {
						"type":     "text"
					},
					"f2" : {
						"type" : "integer"
					}
				}
			}
		}
}

POST/_bulk
{ "index" : { "_index" : "indexscore1", "_type" : "doc", "_id" : "4" } }
{ "type" : "doc", "f1" : "beautiful horse"}

GET /indexscore1/_search
 {
	 "query" : {
		 "function_score": {
				"script_score" : {
					"script" : {
							"source" : "if (doc.containsKey('f2')) {return doc['f2'].value;} return 1.0;"
					}    
				}	
		 }
	 }
 }

I expect that "if (doc.containsKey('f2')) {return doc['f2'].value;} return 1.0;" should return 1 for my doc, but this returns 0:

"hits": [
                     {
				"_index": "indexscore1",
				"_type": "doc",
				"_id": "4",
				"_score": 0.0,
				"_source": {
					"type": "doc",
					"f1": "beautiful horse"
				}
			}
		]

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions