Function score query with field_value_factor on not (yet) existing field
The error you're seeing occurs at query parsing time, i.e. nothing has been executed yet. At that time, the FieldValueFactorFunctionParser
builds the filter_value_factor
function to be executed later, but it notices that the views
field doesn't exist in the mapping type.
Note that the filter has not been executed yet, just like the filter_value_factor
function, it has only been parsed by FunctionScoreQueryParser
.
I'm wondering why you can't simply add a field in your mapping type, it's as easy as running this
curl -XPUT 'http://localhost:9200/blog/_mapping/page' -d '{ "page" : { "properties" : { "views" : {"type" : "integer"} } }}'
If this is REALLY not an option, another possibility would be to use script_score
instead, like this:
{ "query": { "function_score": { "query": { "match": { "author-title": "developer" } }, "functions": [ { "filter": { "range": { "views": { "from": 1 } } }, "script_score": { "script": "_score * doc.views.value" } } ] } }}