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

Make it easier to boost by field value #49761

Open
jpountz opened this issue Dec 2, 2019 · 3 comments
Open

Make it easier to boost by field value #49761

jpountz opened this issue Dec 2, 2019 · 3 comments
Labels
>enhancement :Search Relevance/Ranking Scoring, rescoring, rank evaluation. Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch

Comments

@jpountz
Copy link
Contributor

jpountz commented Dec 2, 2019

I have seen a couple users wanting to boost documents based on the category that documents belong to end up with a query that looked like this:

POST _search
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "body": "apache lucene"
        }
      },
      "functions": [
        {
          "filter": { "match": { "category": "books" } },
          "weight": 5
        },
        ...tens of similar functions
        {
          "filter": { "match": { "category": "food" } },
          "weight": 0.3
        }
      ],
      "score_mode": "first"
    }
  }
}

These queries have tens or hundreds of functions, for each category that they are trying to boost differently, and that need to be evaluated in order until one of them matches (which typically still requires to evaluate half the filters on average since values are usually exclusive). It is possible to do something that usually performs better with a script:

POST _search
{
  "query": {
    "script": {
      "query": {
        "match": {
          "body": "apache lucene"
        }
      },
      "script": {
        "params": {
          "books": 5,
         ...other boosts...
          "food": 0.3
        },
        "source": """if (doc["category"].size() != 0) { params.getOrDefault(doc["category"].value, 0) } else { 0 }"""
      }
    }
  }
}

But it is still far from being ideal. For instance scripts have to do the ordinal->value lookup here while what we'd really want would be to make this work on top of ordinals. This seems to be a common problem to me, can we add a new query that would help solve this problem?

@jpountz jpountz added >feature :Search Relevance/Ranking Scoring, rescoring, rank evaluation. labels Dec 2, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Ranking)

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

Pinging @elastic/es-search (Team:Search)

@javanna javanna added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 12, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Relevance/Ranking Scoring, rescoring, rank evaluation. Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

5 participants