New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatchQueryParser doesn't allow field boosting on query when included in a _GET request #3024

Closed
mikedangelo opened this Issue May 10, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@mikedangelo

mikedangelo commented May 10, 2013

In the following query, we try to boost the FirstLast field by 7 and it fails:

/_search?q=(FirstLast%3A"johnsmith")^7&explain=true
...
_explanation": {

"value": 10,
"description": "weight(FirstLast:johnsmith in 0) [PerFieldSimilarity], result of:"

This behavior works correctly in the MultiMatchQueryParser:
_search?q=(FirstLast%3A"johnsmith")^7+(State%3A"wa")&explain=true
...
"_explanation": {

"value": 80,
"description": "sum of:",
"details": [
    {
        "value": 70,
        "description": "weight(FirstLast:johnsmith^7.0 in 0) [PerFieldSimilarity], result of:",

Note that the boost does work when the request is a _POST as so:
_search" -d '{"query":{"term":{"State":{"value":"wa","boost":7.0}}}}'
{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":1,"max_score":70.0,"hits":[{"_index":"3","_type":"people","_id":"XXXXXXXXXX","_score":70.0, "_source" : {"FirstLast":["johnsmith"],"State":["wa"]}}]}}

I'm just getting used to the code and have no debugger setup yet so forgive me if I'm mistaken or incorrectly using this.

@mattweber

This comment has been minimized.

Contributor

mattweber commented May 20, 2013

Tracked this down. Looks like the parsed query boost is getting reset to the default of 1.0 on this line:

https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java#L217

@kimchy @s1monw Should this line look something like the following?

query.setBoost(query.getBoost() * qpSettings.boost());

If yes, I can open a pull request.

Thanks,
Matt Weber

mattweber added a commit to mattweber/elasticsearch that referenced this issue May 21, 2013

QueryStringQuery overwrites parsed boost value
Set the query boost of a parsed query string query to the product of
the parsed query boost and the boost value specified in the "boost"
query string parameter.

fixes elastic#3024

@ghost ghost assigned s1monw May 21, 2013

@s1monw

This comment has been minimized.

Contributor

s1monw commented May 21, 2013

yeah so the reason why this fails is that the query that we boost with the qpSettings is the topLevelQuery. The fix looks good to me. I will add some more tests and pull it in! thanks matt

@s1monw s1monw closed this in 927fda8 May 21, 2013

s1monw added a commit that referenced this issue May 21, 2013

Apply QueryParser boost to top leve query if applicable.
Set the query boost of a parsed query string query to the product of
the parsed query boost and the boost value specified in the "boost"
query string parameter. This only applies if the top level query returned
from the query parser has a boost assigned to it. In such a case we must
multiply the boost with the top level query boost otherwise the boost
will be overwritten ie. 'foo^2' has a top-level boost of 2 while
'foo^2 OR bar^3' has a top level boost of 1.0 (default) since the
boolean query is the top level query.

Closes #3024

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Apply QueryParser boost to top leve query if applicable.
Set the query boost of a parsed query string query to the product of
the parsed query boost and the boost value specified in the "boost"
query string parameter. This only applies if the top level query returned
from the query parser has a boost assigned to it. In such a case we must
multiply the boost with the top level query boost otherwise the boost
will be overwritten ie. 'foo^2' has a top-level boost of 2 while
'foo^2 OR bar^3' has a top level boost of 1.0 (default) since the
boolean query is the top level query.

Closes elastic#3024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment