# Function score query fails with field\_value\_factor on not (yet) existing field

**URL:** https://discuss.elastic.co/t/function-score-query-fails-with-field-value-factor-on-not-yet-existing-field/23466
**Category:** Elasticsearch
**Created:** [April 29, 2015, 12:13pm UTC](https://discuss.elastic.co/t/function-score-query-fails-with-field-value-factor-on-not-yet-existing-field/23466 "2015-04-29T12:13:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tobias\_Schubotz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_schubotz/32/727_2.png) [@Tobias\_Schubotz](https://discuss.elastic.co/u/Tobias_Schubotz)
#### Post date: [April 29, 2015, 12:13pm UTC](https://discuss.elastic.co/t/function-score-query-fails-with-field-value-factor-on-not-yet-existing-field/23466/1 "2015-04-29T12:13:19Z")

</div>

Hi,

My ES function score query contains several different functions based on a  
set of different fields. I'm having problems with field\_value\_factor on not  
existing fields.  
I'm not sure if that's existing behavior or a bug in ES.

Here a minimal example on how to reproduce the problem:

Example document:  
curl -XPOST "[http://localhost:9200/blog/page/1?pretty](http://localhost:9200/blog/page/1?pretty)" -d '  
{  
"author": "tobias",  
"content": "Great",  
"views": 1  
}'

A search request, that boosts based on the function score looks like that:  
curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
{  
"query": {  
"function\_score": {  
"functions": [  
{  
"field\_value\_factor": {  
"field": "views",  
"modifier": "log2p"  
}  
}  
]  
}  
}  
}'

Everything is fine until this point.  
When I change the "field" param to "likes", the requests fails:  
curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
{  
"query": {  
"function\_score": {  
"functions": [  
{  
"field\_value\_factor": {  
"field": "likes",  
"modifier": "log2p"  
}  
}  
]  
}  
}  
}'  
-\> ElasticsearchException[Unable to find a field mapper for field [likes]

"likes" doesn't exist yet in the "page" document type, but it might exist  
in the future. Or there could be another type "page2", where the "likes"  
field exist, and I need to query both "page" and "page2" in 1 request.

What I tried, is to put an exist filter beforehand, however, the error  
remains the same.  
curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
{  
"query": {  
"function\_score": {  
"functions": [  
{  
"filter": {  
"exists": {  
"field": "likes"  
}  
},  
"field\_value\_factor": {  
"field": "likes"  
}  
}  
]  
}  
}  
}'  
-\> ElasticsearchException[Unable to find a field mapper for field [likes]

Is this a bug or expected bahavior?  
I would expect ES to just skip the function, in case the "exists" filter  
evaluates to False or the field doesn't exist.

With other function types, there is no problem. E.g. the following works  
without an error:  
curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
{  
"query": {  
"function\_score": {  
"functions": [  
{  
"filter": {  
"range": {"likes": {"from": 1}}  
},  
"weight": 1.5  
}  
]  
}  
}  
}'

Any ideas?

Let me know, if you need further information.

Best regards,  
Tobias

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f382e8d1-09f9-410f-ad6b-1a9d7fd8a6b8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f382e8d1-09f9-410f-ad6b-1a9d7fd8a6b8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Tobias\_Schubotz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_schubotz/32/727_2.png) [@Tobias\_Schubotz](https://discuss.elastic.co/u/Tobias_Schubotz)
#### Post date: [April 30, 2015, 8:05am UTC](https://discuss.elastic.co/t/function-score-query-fails-with-field-value-factor-on-not-yet-existing-field/23466/2 "2015-04-30T08:05:18Z")

</div>

The error originates from FieldValueFactorFunctionParser.java  
[https://github.com/elastic/elasticsearch/blob/528f6481eaadd2a0585dc6731a94d7a024b8ce29/src/main/java/org/elasticsearch/index/query/functionscore/fieldvaluefactor/FieldValueFactorFunctionParser.java](https://github.com/elastic/elasticsearch/blob/528f6481eaadd2a0585dc6731a94d7a024b8ce29/src/main/java/org/elasticsearch/index/query/functionscore/fieldvaluefactor/FieldValueFactorFunctionParser.java) (line  
89), in FieldValueFactorFunctionParser.  
Is there really a need to check for the existence of all fields during  
parsing?  
With other function, this is not done, so no problem if a field does not  
exist, yet.

Best regards,  
Tobias

On Wednesday, April 29, 2015 at 2:13:19 PM UTC+2, Tobias Schubotz wrote:

> Hi,
> 
> My ES function score query contains several different functions based on a  
> set of different fields. I'm having problems with field\_value\_factor on not  
> existing fields.  
> I'm not sure if that's existing behavior or a bug in ES.
> 
> Here a minimal example on how to reproduce the problem:
> 
> Example document:  
> curl -XPOST "[http://localhost:9200/blog/page/1?pretty](http://localhost:9200/blog/page/1?pretty)" -d '  
> {  
> "author": "tobias",  
> "content": "Great",  
> "views": 1  
> }'
> 
> A search request, that boosts based on the function score looks like that:  
> curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
> {  
> "query": {  
> "function\_score": {  
> "functions": [  
> {  
> "field\_value\_factor": {  
> "field": "views",  
> "modifier": "log2p"  
> }  
> }  
> ]  
> }  
> }  
> }'
> 
> Everything is fine until this point.  
> When I change the "field" param to "likes", the requests fails:  
> curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
> {  
> "query": {  
> "function\_score": {  
> "functions": [  
> {  
> "field\_value\_factor": {  
> "field": "likes",  
> "modifier": "log2p"  
> }  
> }  
> ]  
> }  
> }  
> }'  
> -\> ElasticsearchException[Unable to find a field mapper for field [likes]
> 
> "likes" doesn't exist yet in the "page" document type, but it might exist  
> in the future. Or there could be another type "page2", where the "likes"  
> field exist, and I need to query both "page" and "page2" in 1 request.
> 
> What I tried, is to put an exist filter beforehand, however, the error  
> remains the same.  
> curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
> {  
> "query": {  
> "function\_score": {  
> "functions": [  
> {  
> "filter": {  
> "exists": {  
> "field": "likes"  
> }  
> },  
> "field\_value\_factor": {  
> "field": "likes"  
> }  
> }  
> ]  
> }  
> }  
> }'  
> -\> ElasticsearchException[Unable to find a field mapper for field [likes]
> 
> Is this a bug or expected bahavior?  
> I would expect ES to just skip the function, in case the "exists" filter  
> evaluates to False or the field doesn't exist.
> 
> With other function types, there is no problem. E.g. the following works  
> without an error:  
> curl -XPOST "[http://localhost:9200/blog/\_search](http://localhost:9200/blog/_search)" -d '  
> {  
> "query": {  
> "function\_score": {  
> "functions": [  
> {  
> "filter": {  
> "range": {"likes": {"from": 1}}  
> },  
> "weight": 1.5  
> }  
> ]  
> }  
> }  
> }'
> 
> Any ideas?
> 
> Let me know, if you need further information.
> 
> Best regards,  
> Tobias

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36dfe2bf-b6c1-4d85-8e53-61526453bdc2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36dfe2bf-b6c1-4d85-8e53-61526453bdc2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 12:16am UTC](https://discuss.elastic.co/t/function-score-query-fails-with-field-value-factor-on-not-yet-existing-field/23466/3 "2017-07-06T00:16:48Z")

</div>


