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

Compound query #51967

Closed
mayya-sharipova opened this issue Feb 5, 2020 · 5 comments
Closed

Compound query #51967

mayya-sharipova opened this issue Feb 5, 2020 · 5 comments
Assignees
Labels
>feature :Search/Search Search-related issues that do not fall into other categories

Comments

@mayya-sharipova
Copy link
Contributor

This is related to #42811 -- deprecating function_score query

A proposal is to have a new type of compound query that has an ability to combine scores from different queries:

{
  "query": {
    "compound": {
      "queries": [
        {
          "match": {"message": "elasticsearch"}
        },
        {
         "match": {"author": "shay banon"}
        }
      ],
      "combine_mode": "sum"
    }
  }
}

combine_mode has the same values and definitions as in Function Score Query's score_mode

combine_mode definition
sum scores are summed (default)
multiply scores are multiplied
avg scores are averaged
first the first function that has a matching filter is applied
max maximum score is used
min minimum score is used

The intention for this query is to allow custom scoring logic, so internal queries are primarily expected to be script_score queries. For example, the intention fo the following query is to find "best fit" candidate with necessary skills:

{
  "query": {
    "compound": {
      "queries": [
        {
          "script_score": {
            "query": {
              "match": {
                "skills": "Java"
              }
            },
            "script": { "source": "10.0"}
          }
        },
        {
          "script_score": {
            "query": {
              "match": {
                "skills": "Scala"
              }
            },
            "script": {"source": "5.0"}
          }
        },
        {
          "script_score": {
            "query": {
              "match": {
                "skills": "Python"
              }
            },
            "script": {"source": "1.0"}
          }
        }
      ],
      "combine_mode": "first"
    }
  }
}
@mayya-sharipova mayya-sharipova added the :Search/Search Search-related issues that do not fall into other categories label Feb 5, 2020
@elasticmachine
Copy link
Collaborator

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

@mayya-sharipova mayya-sharipova self-assigned this Feb 5, 2020
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Feb 14, 2020
This introduces compound query that allows to combine
scores from wrapped queries in a number of ways:

{
  "query": {
    "compound": {
      "queries": [
        {
          "match": {"message": "elasticsearch"}
        },
        {
         "match": {"author": "shay banon"}
        }
      ],
      "combine_mode": "sum"
    }
  }
}

Options for combine_mode:
sum, multiply, avg, first, max, min

compound query allows to deprecate function_score query.

closes elastic#51967
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Feb 17, 2020
This introduces compound query that allows to combine
scores from wrapped queries in a number of ways:

{
  "query": {
    "compound": {
      "queries": [
        {
          "match": {"message": "elasticsearch"}
        },
        {
         "match": {"author": "shay banon"}
        }
      ],
      "combine_mode": "sum"
    }
  }
}

Options for combine_mode:
sum, multiply, avg, first, max, min

compound query allows to deprecate function_score query.

closes elastic#51967
@mayya-sharipova
Copy link
Contributor Author

Closing this issue, as it is replaced by #52482

mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Feb 19, 2020
This introduces compound query that allows to combine
scores from wrapped queries in a number of ways:

{
  "query": {
    "compound": {
      "queries": [
        {
          "match": {"message": "elasticsearch"}
        },
        {
         "match": {"author": "shay banon"}
        }
      ],
      "combine_mode": "sum"
    }
  }
}

Options for combine_mode:
sum, multiply, avg, first, max, min

compound query allows to deprecate function_score query.

closes elastic#51967
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Jun 17, 2022
We had a plan to deprecate function_score query with
script_score query, but ran into a roadblock of missing
functionality to combine scores from different
functions (particularly "first" script_score).
Wee have several proposal to address this missing
functionality:
 [scripted_boolean](elastic#27588 (comment))
 [compound_query](elastic#51967)
 [first_query](elastic#52482)

But for now, we decided not to deprecate function_score query,
and hence we need to remove any mention that we are deprecating it.

Relates to elastic#42811
Closes elastic#71934
mayya-sharipova added a commit that referenced this issue Jun 17, 2022
We had a plan to deprecate function_score query with
script_score query, but ran into a roadblock of missing
functionality to combine scores from different
functions (particularly "first" script_score).
Wee have several proposal to address this missing
functionality:
 [scripted_boolean](#27588 (comment))
 [compound_query](#51967)
 [first_query](#52482)

But for now, we decided not to deprecate function_score query,
and hence we need to remove any mention that we are deprecating it.

Relates to #42811
Closes #71934
mayya-sharipova added a commit that referenced this issue Jun 17, 2022
We had a plan to deprecate function_score query with
script_score query, but ran into a roadblock of missing
functionality to combine scores from different
functions (particularly "first" script_score).
Wee have several proposal to address this missing
functionality:
 [scripted_boolean](#27588 (comment))
 [compound_query](#51967)
 [first_query](#52482)

But for now, we decided not to deprecate function_score query,
and hence we need to remove any mention that we are deprecating it.

Relates to #42811
Closes #71934
mayya-sharipova added a commit that referenced this issue Jun 17, 2022
We had a plan to deprecate function_score query with
script_score query, but ran into a roadblock of missing
functionality to combine scores from different
functions (particularly "first" script_score).
Wee have several proposal to address this missing
functionality:
 [scripted_boolean](#27588 (comment))
 [compound_query](#51967)
 [first_query](#52482)

But for now, we decided not to deprecate function_score query,
and hence we need to remove any mention that we are deprecating it.

Relates to #42811
Closes #71934
@jayaddison
Copy link

jayaddison commented Jun 17, 2022

Hi @mayya-sharipova - closing of the linked issue reminded me of this, and I noticed that there was an implementation in-progress at one point (#52387). Are there any plans to introduce something like a compound query in ES in future? (it's ok either way, I'm just curious)

Edit: sorry, in hindsight I should've waited until after the weekend to ask about this. It's neither urgent nor important, just something I'm interested in.

@mayya-sharipova
Copy link
Contributor Author

@jayaddison Thank you for your interest. We did not pursue this work till the end, as we had some other priorities to work on. We will try to re-discuss this topic and get back to it.

@jayaddison
Copy link

jayaddison commented Jun 20, 2022

Thanks @mayya-sharipova, that makes sense.

At the risk of over-communicating: I've removed my upvote from this issue because I don't know for certain whether compound queries would address my use case. I'll rephrase my problem as a feature request (linked to this one for the possibility of relevance) to try to gauge whether it has support.

(in other words: don't feel any pressure to re-discuss this; that may not be required unless other people want this query functionality)

Edit: feature requested opened as issue 88086 - I'm not #mentioning that issue number intentionally because I think it would introduce more noise than value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants