I have been dealing with this problem for a long time and can not figure it out.
Take the following case:
I have 2 employees in my company who have their own blog page:
POST blog/page/1 { "author": "Byron", "author-title": "Junior Software Developer", "content" : "My amazing bio" }
and
POST blog/page/2 { "author": "Jason", "author-title": "Senior Software Developer", "content" : "My amazing bio is better" }
After they created their blog posts, we would like to track the โviewsโ of their blogs and increase search results based on their โviewsโ.
This can be done using the function evaluation query:
GET blog/_search { "query": { "function_score": { "query": { "match": { "author-title": "developer" } }, "functions": [ { "filter": { "range": { "views": { "from": 1 } } }, "field_value_factor": { "field": "views" } } ] } } }
I use a range filter to make sure that field_value_factor does not affect the rating when the number of views is 0 (the rating will also be 0).
Now, when I try to run this query, I will get the following exception:
nested: ElasticsearchException[Unable to find a field mapper for field [views]]; }]
This makes sense because the field does not exist anywhere in the index. If I added views = 0 by the time index, I would not have the above problem, since this field is known in the index. But in my use case, I cannot add this either by time index or by matching.
Based on the ability to use a range filter in a function evaluation request, I thought I could use
Still gives:
nested: ElasticsearchException[Unable to find a field mapper for field [views]]; }]
Where would I expect Elasticsearch to apply a filter first before parsing field_value_factor.
Any thoughts on how to fix this problem without using map files or fixes during indexing or scripts?