Skip to content
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

inconsistent behavior and documentation(?) errors with function_score #3872

Closed
Xylakant opened this Issue Oct 10, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@Xylakant
Copy link

commented Oct 10, 2013

Trying to use the new function_score query in 0.90.5 I stumbled across some errors. In a couple of cases the code does not work as documented.

boost_mode multiply

Using "boost_mode": "multiply" fails:

{
    "query": {
        "function_score": {
            "boost_mode": "multiply",
            "query": {
                "match": {
                    "title": "elasticsearch"
                }
            },
            "functions": [
                {
                    "gauss": {
                        "date": {
                            "scale": "4w"
                        }
                    }
                }
            ]
        }
    }
}

result:

QueryParsingException[[psb-1.1] function_score illegal boost_mode [multiply]]

"boost_mode": "mult" works. However, score_mode just behaves the other way round:

QueryParsingException[[psb-1.1] function_score illegal score_mode [mult]];

boost as decay_function

Both the blog post introducing the feature and the documentation propose a query along the lines of

"query": {
  "function_score": {
    "query": {
      "match": { "title": "elasticsearch"}
    },
    "functions": [
      { "boost":  1 },
      {
        "gauss": {
          "timestamp": {
            "scale": "4w"
          }
        }
      }
    ],
    "score_mode": "sum"
  }
}

respectively

"function_score": {
    "functions": [
        {
            "boost": "3",
            "filter": {...}
        },
        {
            "filter": {...},
            "script_score": {
                "params": {
                    "param1": 2,
                    "param2": 3.1
                },
                "script": "_score * doc['my_numeric_field'].value / pow(param1, param2)"
            }
        }
    ],
    "query": {...},
    "score_mode": "first"
}

The second sample is intended to provide a replacement for the custom_filters_score_query. However, the first example fails against 0.90.5 with the following trace:

Parse Failure [Failed to parse source [{ "query": { "function_score": { "query": { "match": { "title": "elasticsearch" } }, "functions": [ { "boost": 1 }, { "gauss": { "timestamp": { "scale": "4w" } } } ], "score_mode": "sum" } } }]]]; nested: QueryParsingException[[psb-1.1] No function with the name [boost] is registered.]; }

I failed to figure out what's the right incantation to invoke boost.

@ghost ghost assigned brwe Oct 10, 2013

@brwe

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2013

"boost_mode": "mult" is indeed wrong, it was supposed to be working with "boost_mode": "multiply". I will fix this.

As for the boost function, the documentation is wrong. The keyword is "boost_factor" instead of "boost". I will update the documentation accordingly.

Thanks a lot for reporting this!

@Xylakant

This comment has been minimized.

Copy link
Author

commented Oct 10, 2013

If multiply is the right keyword to use with boost_mode, the first two samples in the doc are false as well since they still mention mult:

"function_score": {
    "(query|filter)": {},
    "boost": "boost for the whole query",
    "FUNCTION": {},
    "boost_mode":"(mult|replace|...)"
}

and

"function_score": {
    "(query|filter)": {},
    "boost": "boost for the whole query",
    "functions": [
        {
            "filter": {},
            "FUNCTION": {}
        },
        {
            "FUNCTION": {}
        }
    ],
    "max_boost": number,
    "score_mode": "(mult|max|...)",
    "boost_mode": "(mult|replace|...)"
}

Thanks for the quick response.

brwe added a commit to brwe/elasticsearch that referenced this issue Oct 14, 2013

fix naming in function_score
    - "boost" should be "boost_factor"
    - rename "mult" to "multiply"

Because "mult" was introduced in 0.94, we keep both names and remove "mult"
completly from 1.0 on.

closes elastic#3872 for 0.90

brwe added a commit to brwe/elasticsearch that referenced this issue Oct 14, 2013

fix naming in function_score
    - "boost" should be "boost_factor"
    - "mult" should be "multiply"

Also, store combine function names in ImmutableMap instead of iterating
over all possible names each time.

closes elastic#3872 for master

brwe added a commit that referenced this issue Oct 14, 2013

fix naming in function_score
    - "boost" should be "boost_factor"
    - rename "mult" to "multiply"

Because "mult" was introduced in 0.90.4, we keep both names and remove "mult"
completly from 1.0 on.

closes #3872 for 0.90

@brwe brwe closed this in 34441f3 Oct 14, 2013

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

fix naming in function_score
    - "boost" should be "boost_factor"
    - rename "mult" to "multiply"

Because "mult" was introduced in 0.90.4, we keep both names and remove "mult"
completly from 1.0 on.

closes elastic#3872 for 0.90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.