how to deal with null values in an elastic search field_value_factor
ES's default behavior for null values is to not add the field value at all. However, you can set a default null_value instead, in your mapping. So in your case:
...
"properties" : {
...
"popularity" : {
"type" : "integer",
"null_value" : "0" # or whatever
...
}
...
}
Reference: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
"When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field at all."
I'm surprised ES is not throwing any errors. You should confirm the documents actually do (or don't) have your 'popularity' field. Try using Sense?
If you try to compute on a non-existent field, I'm pretty sure ES would throw a [Missing value for field [x]] exception. This is both from my own experience and from checking the source code that implements field_value_factor:
https://gitlab.devero.com/development/elasticsearchssl/commit/8fbd1bdd489a9d31d3bda249c3ed9715052e196d
Scroll down to: src/main/java/org/elasticsearch/common/lucene/search/function/FieldValueFactorFunction.java
and look at lines 53-87.