Skip to content

[Multi Match] Refactor QueryIntercepter Rewrite #132026

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Samiul-TheSoccerFan
Copy link
Contributor

@Samiul-TheSoccerFan Samiul-TheSoccerFan commented Jul 28, 2025

This PR is the first part of multi_match implementation with semantic_text field.

This PR includes:

  • Update getFieldName to handle fieldName along with its per field boost.
  • supply field boost value into each intercepter.
  • Update intercepter framework to handle the updated function name.
PUT my_documents
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "content": {
        "type": "text"
      }
    }
  }
}

PUT my_documents/_doc/1
{ 
  "title": "Introduction to Machine Learning",
  "content": "This guide covers supervised and unsupervised learning." 
}

PUT my_documents/_doc/2
{ 
  "title": "Solar Panels for Beginners",
  "content": "Learn how solar energy works and its benefits."
}

POST my_documents/_search --works as expected
{
  "query": {
    "multi_match": {
      "query": "learn solar energy",
      "fields": ["title", "content^2"],
      "boost": 3.0
    }
  }
}


PUT my_semantic_documents
{
  "mappings": {
    "properties": {
      "title": {
        "type": "semantic_text"
      }
    }
  }
}

PUT my_semantic_documents/_doc/1
{ 
  "title": "Introduction to Machine Learning"
}

PUT my_semantic_documents/_doc/2
{ 
  "title": "Solar Panels for Beginners"
}

POST my_semantic_documents/_search -- fails as expected
{
  "query": {
    "multi_match": {
      "query": "learn solar energy",
      "fields": [
        "title^2"
      ],
      "boost": 3.0,
      "_name": "semantic_query"
    }
  }
}

PUT my_another_semantic_documents
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "content": {
        "type": "semantic_text"
      }
    }
  }
}

PUT my_another_semantic_documents/_doc/1
{ 
  "title": "Introduction to Machine Learning",
  "content": "This guide covers supervised and unsupervised learning." 
}

PUT my_another_semantic_documents/_doc/2
{ 
  "title": "Solar Panels for Beginners",
  "content": "Learn how solar energy works and its benefits."
}

POST my_another_semantic_documents/_search -- fails as expected
{
  "query": {
    "multi_match": {
      "query": "learn solar energy",
      "fields": [
        "title",
        "content"
      ]
    }
  }
}

@Samiul-TheSoccerFan Samiul-TheSoccerFan added >enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search - Relevance The Search organization Search Relevance team v9.2.0 labels Jul 28, 2025
@elasticsearchmachine elasticsearchmachine added the Team:SearchOrg Meta label for the Search Org (Enterprise Search) label Jul 28, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @Samiul-TheSoccerFan, I've created a changelog YAML for you.

Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a changelog for this PR. Let's label it as >refactor to remove that.

@@ -33,14 +33,17 @@ public SemanticQueryRewriteInterceptor() {}

@Override
public QueryBuilder interceptAndRewrite(QueryRewriteContext context, QueryBuilder queryBuilder) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this method are not effectively preparing for the changes that will actually necessary to support multi_match here. I suggest taking some time to think about how you will change this method to properly support multi_match, making an implementation plan, and then determining which parts of that plan can and should be done as part of this initial refactor PR.

@Samiul-TheSoccerFan
Copy link
Contributor Author

@elasticmachine update branch

@Samiul-TheSoccerFan
Copy link
Contributor Author

@elasticmachine update branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search - Relevance The Search organization Search Relevance team Team:SearchOrg Meta label for the Search Org (Enterprise Search) v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants