# Custom\_filter\_score not working with nested query

**URL:** <https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771>\
**Category:** Elasticsearch\
**Created:** [November 4, 2011, 11:47am UTC](https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771 "2011-11-04T11:47:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [November 4, 2011, 11:47am UTC](https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771/1 "2011-11-04T11:47:05Z")

</div>

Hi.

I was using custrom\_filter\_score for customized scoring and it was working  
perfect, but when i put the query in the nested query, it stopped giving me  
the customized score, and started giving me the natural scoring, which is  
not desireable, can you please tell me, what is wrong with it, and where  
should i use the nestest query as my query structure is as follows:

{  
"query": {  
"nested": {  
"path": "searchable",  
"query": {  
"custom\_filters\_score": {  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
[  
{  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
"query": "un",  
"analyzer": "simple"  
}  
}  
},  
{  
"text": {  
"searchable.code": {  
"type": "phrase\_prefix",  
"query": "un",  
"analyzer": "keyword"  
}  
}  
},  
{  
"text": {  
"searchable.zip": {  
"type": "phrase\_prefix",  
"query": "un"  
}  
}  
}  
]  
]  
}  
},  
"filter": {  
"or": [  
{  
"prefix": {  
"searchable.title": "un"  
}  
},  
{  
"prefix": {  
"searchable.code": "un"  
}  
},  
{  
"prefix": {  
"searchable.zip": "un"  
}  
}  
]  
}  
}  
},  
"filters": [  
{  
"filter": {  
"term": {  
"case 1": "xyz"  
}  
},  
"script": 10  
},  
{  
"filter": {  
"term": {  
"type": "abc"  
}  
},  
"script": 6  
}  
],  
"score\_mode": [  
"total"  
]  
}  
}  
}  
},  
"size": 10,  
"from": 0  
}

---

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [November 5, 2011, 3:58am UTC](https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771/2 "2011-11-05T03:58:30Z")

</div>

This is the new Query..

{  
"query": {  
"custom\_filters\_score": {  
"query": {  
"nested": {  
"path": "searchable",  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"should": [  
[  
{  
"text": {  
"searchable.title": {  
"type": "phrase\_prefix",  
"query": "un",  
"analyzer": "simple"  
}  
}  
},  
{  
"text": {  
"searchable.code": {  
"type": "phrase\_prefix",  
"query": "un",  
"analyzer": "keyword"  
}  
}  
},  
{  
"text": {  
"searchable.zip": {  
"type": "phrase\_prefix",  
"query": "un"  
}  
}  
}  
]  
]  
}  
},  
"filter": {  
"or": [  
{  
"prefix": {  
"searchable.title": "un"  
}  
},  
{  
"prefix": {  
"searchable.code": "un"  
}  
},  
{  
"prefix": {  
"searchable.zip": "un"  
}  
}  
]  
}  
}  
}  
}  
},  
"filters": [  
{  
"filter": {  
"term": {  
"follower\_of\_inverse": "34"  
}  
},  
"script": 100  
},  
{  
"filter": {  
"term": {  
"type": "user"  
}  
},  
"script": 60  
},  
{  
"filter": {  
"term": {  
"type": "object"  
}  
},  
"script": 0  
},  
{  
"filter": {  
"term": {  
"entity\_type": "identity"  
}  
},  
"script": 30  
},  
{  
"filter": {  
"term": {  
"entity\_type": "interest"  
}  
},  
"script": 0  
},  
{  
"filter": {  
"term": {  
"subtype": "izapgeocountry"  
}  
},  
"script": 9  
},  
{  
"filter": {  
"term": {  
"subtype": "izapgeostate"  
}  
},  
"script": 7  
},  
{  
"filter": {  
"term": {  
"subtype": "izapgeoregion"  
}  
},  
"script": 5  
},  
{  
"filter": {  
"term": {  
"subtype": "izapgeocity"  
}  
},  
"script": 3  
},  
{  
"filter": {  
"term": {  
"subtype": "izapgeoneighborhood"  
}  
},  
"script": 1  
},  
{  
"filter": {  
"term": {  
"truly\_verified": "yes"  
}  
},  
"script": 2  
}  
],  
"score\_mode": [  
"total"  
]  
}  
},  
"size": null,  
"from": null  
}

And the Error now I am getting is :

- failures: [
  - {
    - index: narinder
    - shard: 0
    - status: 500
    - reason: QueryPhaseExecutionException[[narinder][0]: query[custom  
score (BlockJoinQuery (filtered(filtered(searchable.title:"un"  
searchable.code:"un"  
searchable.zip:"un")-\>org.elasticsearch.common.lucene.search.OrFilter@de2a3af8)-\>FilterCacheFilterWrapper(\_type:\_\_searchable)),  
functions: [{filter(FilterCacheFilterWrapper(follower\_of\_inverse:34)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@1845cce]}{filter(FilterCacheFilterWrapper(type:user)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@e914a8]}{filter(FilterCacheFilterWrapper(type:object)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@4b44f0]}{filter(FilterCacheFilterWrapper(entity\_type:identity)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@19afa26]}{filter(FilterCacheFilterWrapper(entity\_type:interest)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@19d142f]}{filter(FilterCacheFilterWrapper(subtype:izapgeocountry)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@1985910]}{filter(FilterCacheFilterWrapper(subtype:izapgeostate)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@ff2c4e]}{filter(FilterCacheFilterWrapper(subtype:izapgeoregion)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@b5e07a]}{filter(FilterCacheFilterWrapper(subtype:izapgeocity)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@a488b9]}{filter(FilterCacheFilterWrapper(subtype:izapgeoneighborhood)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@c4ef1]}{filter(FilterCacheFilterWrapper(truly\_verified:yes)),  
function  
[org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@12c5c8]}])],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested:  
}  
]

}

BUt this error is just temp. It only shows up sometimes, but if i just wait  
for some time approx for 5 mins, this query runs fine and gives me the  
results.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 8, 2011, 3:46am UTC](https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771/3 "2011-11-08T03:46:54Z")

</div>

Can you _gist_ the failure logged by elasticsearch.

On Sat, Nov 5, 2011 at 5:58 AM, Narinder Kaur [narinder.kaur@izap.in](mailto:narinder.kaur@izap.in) wrote:

> This is the new Query..
> 
> {  
> "query": {  
> "custom\_filters\_score": {  
> "query": {  
> "nested": {  
> "path": "searchable",  
> "query": {  
> "filtered": {  
> "query": {  
> "bool": {  
> "should": [  
> [  
> {  
> "text": {  
> "searchable.title": {  
> "type": "phrase\_prefix",  
> "query": "un",  
> "analyzer": "simple"  
> }  
> }  
> },  
> {  
> "text": {  
> "searchable.code": {  
> "type": "phrase\_prefix",  
> "query": "un",  
> "analyzer": "keyword"  
> }  
> }  
> },  
> {  
> "text": {  
> "searchable.zip": {  
> "type": "phrase\_prefix",  
> "query": "un"  
> }  
> }  
> }  
> ]  
> ]  
> }  
> },  
> "filter": {  
> "or": [  
> {  
> "prefix": {  
> "searchable.title": "un"  
> }  
> },  
> {  
> "prefix": {  
> "searchable.code": "un"  
> }  
> },  
> {  
> "prefix": {  
> "searchable.zip": "un"  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> },  
> "filters": [  
> {  
> "filter": {  
> "term": {  
> "follower\_of\_inverse": "34"  
> }  
> },  
> "script": 100  
> },  
> {  
> "filter": {  
> "term": {  
> "type": "user"  
> }  
> },  
> "script": 60  
> },  
> {  
> "filter": {  
> "term": {  
> "type": "object"  
> }  
> },  
> "script": 0  
> },  
> {  
> "filter": {  
> "term": {  
> "entity\_type": "identity"  
> }  
> },  
> "script": 30  
> },  
> {  
> "filter": {  
> "term": {  
> "entity\_type": "interest"  
> }  
> },  
> "script": 0  
> },  
> {  
> "filter": {  
> "term": {  
> "subtype": "izapgeocountry"  
> }  
> },  
> "script": 9  
> },  
> {  
> "filter": {  
> "term": {  
> "subtype": "izapgeostate"  
> }  
> },  
> "script": 7  
> },  
> {  
> "filter": {  
> "term": {  
> "subtype": "izapgeoregion"  
> }  
> },  
> "script": 5  
> },  
> {  
> "filter": {  
> "term": {  
> "subtype": "izapgeocity"  
> }  
> },  
> "script": 3  
> },  
> {  
> "filter": {  
> "term": {  
> "subtype": "izapgeoneighborhood"  
> }  
> },  
> "script": 1  
> },  
> {  
> "filter": {  
> "term": {  
> "truly\_verified": "yes"  
> }  
> },  
> "script": 2  
> }  
> ],  
> "score\_mode": [  
> "total"  
> ]  
> }  
> },  
> "size": null,  
> "from": null  
> }
> 
> And the Error now I am getting is :
> 
> - failures: [
> - {
> - index: narinder
> - shard: 0
> - status: 500
> - reason: QueryPhaseExecutionException[[narinder][0]:  
> query[custom score (BlockJoinQuery (filtered(filtered(searchable.title:"un"  
> searchable.code:"un"  
> searchable.zip:"un")-\>org.elasticsearch.common.lucene.search.OrFilter@de2a3af8)-\>FilterCacheFilterWrapper(\_type:\_\_searchable)),  
> functions: [{filter(FilterCacheFilterWrapper(follower\_of\_inverse:34)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@1845cce]}{filter(FilterCacheFilterWrapper(type:user)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@e914a8]}{filter(FilterCacheFilterWrapper(type:object)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@4b44f0]}{filter(FilterCacheFilterWrapper(entity\_type:identity)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@19afa26]}{filter(FilterCacheFilterWrapper(entity\_type:interest)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@19d142f]}{filter(FilterCacheFilterWrapper(subtype:izapgeocountry)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@1985910]}{filter(FilterCacheFilterWrapper(subtype:izapgeostate)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@ff2c4e]}{filter(FilterCacheFilterWrapper(subtype:izapgeoregion)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@b5e07a]}{filter(FilterCacheFilterWrapper(subtype:izapgeocity)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@a488b9]}{filter(FilterCacheFilterWrapper(subtype:izapgeoneighborhood)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@c4ef1]}{filter(FilterCacheFilterWrapper(truly\_verified:yes)),  
> function  
> [org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction@12c5c8]}])],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested:  
> }  
> ]
> 
> }
> 
> BUt this error is just temp. It only shows up sometimes, but if i just  
> wait for some time approx for 5 mins, this query runs fine and gives me the  
> results.

---

<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, 3:49am UTC](https://discuss.elastic.co/t/custom-filter-score-not-working-with-nested-query/5771/4 "2017-07-06T03:49:39Z")

</div>


