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

Allow post_filter access to the _score #20131

Closed
dmitry opened this issue Aug 23, 2016 · 16 comments
Closed

Allow post_filter access to the _score #20131

dmitry opened this issue Aug 23, 2016 · 16 comments
Labels
>enhancement help wanted adoptme high hanging fruit :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@dmitry
Copy link
Contributor

dmitry commented Aug 23, 2016

I found it's allowed to access _score inside the aggs, but not allowed to access this field in the post_filter queries, though it's executed after the aggs. Is there a reason for that or it could be added?

An example query:

{
  "body": {
    "post_filter": {
      "script": {
        "script": "_score > 100 && _score < 200"
      }
    },
    "query": {
      "function_score": {
        "functions": [{
          "script_score": {
            "script": "doc['price'].value * 100"
          }
        }]
      }
    }
  },
  "index": ["items"],
  "type": []
}

script_score could be much more complex, it's just an example.

More than that I cannot find a solution to that problem: http://stackoverflow.com/questions/39109511/how-to-filter-by-script-field-in-elasticsearch?noredirect=1&lq=1

@s1monw
Copy link
Contributor

s1monw commented Aug 23, 2016

@s1monw s1monw closed this as completed Aug 23, 2016
@dmitry
Copy link
Contributor Author

dmitry commented Aug 23, 2016

@s1monw do you mean in my example I have to use script with doc['price'].value * 100 in the post_filter? What about performance? It's definitely not easy to control script for both, as I would like to use _score inside the aggs afterwards. So search query will be slower at least 2x times, or even more...

@dmitry
Copy link
Contributor Author

dmitry commented Aug 26, 2016

Hey guys, @uboness and @jpountz, please comment.

@dmitry
Copy link
Contributor Author

dmitry commented Sep 2, 2016

Really need this feature, as score calculation in each filter slows down our search. What can I do to push it forward?

@clintongormley clintongormley added discuss :Search/Search Search-related issues that do not fall into other categories labels Sep 2, 2016
@clintongormley
Copy link

@jpountz is there any reason why the _score is not available in a post_filter?

@jpountz
Copy link
Contributor

jpountz commented Sep 23, 2016

Agreed it'd be nice for scores to be available to post filters but there is no way that I can think of that we can propagate the information today.

@dmitry
Copy link
Contributor Author

dmitry commented Sep 23, 2016

@jpountz does it mean it cannot be implemented in the nearest future?

@gm42
Copy link
Contributor

gm42 commented Sep 26, 2016

Is it not possible to propagate the information because there is no "formal" channel of communication between scoring and post_filter in current ES?

@jpountz
Copy link
Contributor

jpountz commented Sep 26, 2016

Yes. In short, the script query returns an implementation of the Lucene Query API that uses a script internally, and the Query API does not give ways to propagate scores so that scripts can be made aware of them. We could hack it in the case that the post filter only contains a script query (if the query is an instance of that class, then get back the wrapped script and pass the scorer object to it so that it can be aware of the scores), but that would not work in the general case, for instance if the query in the post filter is a compound query (eg. bool) with script queries on the leaves.

@gm42
Copy link
Contributor

gm42 commented Sep 27, 2016

@jpountz thanks for the reply. Since situation is like that, shouldn't this feature request be abstracted to a more general "access computed fields in post_filter"?

In an ideal scenario (not really an ES expert here, please bear with me) one could compute via scripts multiple "virtual" script fields and then use them in the post_filter. I know that this possibility would have an impact on the memory usage since reduction would require more buffers, but just throwing it there as it seems a common use-case...

@dmitry
Copy link
Contributor Author

dmitry commented Sep 29, 2016

I still hope the _score could be accessed in a post_filter this year :)

For more details also look to the #10767 (use-case is quite often)

@izaakschroeder
Copy link

Any update on this issue? Using query points for pagination and score sorting really depends on having this! 😄

@dmitry
Copy link
Contributor Author

dmitry commented Jan 5, 2017

@izaakschroeder I also had such usecase, would be great if anyone from the ES team can look into that soon.

@cbuescher
Copy link
Member

cc @elastic/es-search-aggs

@rjernst rjernst added the Team:Search Meta label for search team label May 4, 2020
@gm4git
Copy link

gm4git commented Sep 30, 2021

Any news on this?

@javanna
Copy link
Member

javanna commented Oct 13, 2022

This is a rather old issue that is not straight-forward to address and we don't have plans to work on at this time, hence I am closing it.

@javanna javanna closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement help wanted adoptme high hanging fruit :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

No branches or pull requests

10 participants