Reputation: 4803
I ran these following queries. This query gives me proper score as expected.
{
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
},
{
"match": {
"locationtags_snow": "gyms"
}
},
{
"match": {
"offerings_snow": ""
}
},
{
"match": {
"title_snow": "gyms"
}
},
{
"match": {
"locationcluster_snow": "gyms"
}
},
{
"match": {
"facilities_snow": "gyms in bandra"
}
},
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
},
"functions": [
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 8
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationtags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 10
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"offerings_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 4
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"title_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 12
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationcluster_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"facilities_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 6
}
],
"boost_mode": "max",
"score_mode": "sum"
}
},
"filter": {
"bool": {
"must": [
{
"term": {
"city": "bankok"
}
}
]
}
}
}
}
}
While this query where i am using post_filter to wrap my query is not computing desired score(score is always 1)
{
"post_filter": {
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
},
{
"match": {
"locationtags_snow": "gyms"
}
},
{
"match": {
"offerings_snow": "gyms"
}
},
{
"match": {
"title_snow": "gyms "
}
},
{
"match": {
"locationcluster_snow": "gyms"
}
},
{
"match": {
"facilities_snow": "gyms"
}
},
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
},
"functions": [
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"categorytags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 8
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationtags_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 10
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"offerings_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 4
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"title_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 12
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"locationcluster_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"facilities_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 2
},
{
"filter": {
"query": {
"bool": {
"should": [
{
"match": {
"info_service_snow": "gyms"
}
}
]
}
}
},
"boost_factor": 6
}
],
"score_mode": "sum"
}
},
"filter": {"bool": {
"must": [
{
"term": {
"city": "bankok"
}
}
]
}}
}
}
}
}
Is it like query inside post_filter don't support function_score.
Thanks in advance
Upvotes: 1
Views: 862
Reputation: 217564
This is expected, as stated in the official doc and the definitive guide, anything in post_filter
will run after the query has executed and will not affect the query scope, hence will not affect the score either.
Besides post_filter
is a basically a filter and filters do not affect scoring, score 1 is always returned.
Upvotes: 3