Custom_filter_score not working with nested query

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
}

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.

Can you gist the failure logged by elasticsearch.

On Sat, Nov 5, 2011 at 5:58 AM, Narinder Kaur 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.