- Notifications
You must be signed in to change notification settings - Fork 25.7k
Add match support for semantic_text fields #117839
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
Merged
kderusso merged 90 commits into elastic:main from kderusso:kderusso/semantic-text-match-query-support Dec 12, 2024
Merged
Changes from 81 commits
Commits
Show all changes
90 commits Select commit Hold shift + click to select a range
62e8aa7 Added query name to inference field metadata
Mikep86 43e65eb Fix build error
Mikep86 39eaa56 Added query builder service
Mikep86 e633aa6 Add query builder service to query rewrite context
Mikep86 9c06b6e Updated match query to support querying semantic text fields
Mikep86 db02010 Fix build error
Mikep86 6956ffb Fix NPE
kderusso 3235130 Update the POC to rewrite to a bool query when combined inference and…
kderusso 05638af Separate clause for each inference index (to avoid inference ID clashes)
kderusso 74b4346 Simplify query builder service concept to a single default inference …
kderusso 720be53 Rename QueryBuilderService, remove query name from inference metadata
kderusso 6197541 Fix too many rewrite rounds error by injecting booleans in constructo…
kderusso c8a576c Fix test compilation errors
kderusso a1c3e66 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso bcb93c3 Fix tests
kderusso 6e6e88f Add yaml test for semantic match
kderusso 727e0f1 Add NodeFeature
kderusso 185afa0 Fix license headers
kderusso b4dc5d4 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso 4211f24 Spotless
kderusso d9bc033 Updated getClass comparison in MatchQueryBuilder
kderusso f9e283f Cleanup
kderusso 6fe8d66 Add Mock Inference Query Builder Service
kderusso f99ae91 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso f219ff3 Spotless
kderusso 4232154 Cleanup
kderusso 1e2fb8f Update docs/changelog/117839.yaml
kderusso 84901e2 Update changelog
kderusso 4b5ca9f Replace the default inference query builder with a query rewrite inte…
kderusso 11b3efa Cleanup
kderusso ec5d333 Some more cleanup/renames
kderusso 5c6703e Some more cleanup/renames
kderusso fcd4c85 Spotless
kderusso 296a28c Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso c7f90ae Checkstyle
kderusso 9640ad1 Convert List<QueryRewriteInterceptor> to Map keyed on query name, err…
kderusso bc7f735 PR feedback - remove check on QueryRewriteContext class only
kderusso 9b7b7d2 PR feedback
kderusso b97d148 Remove intercept flag from MatchQueryBuilder and replace with wrapper
kderusso 3be4e83 Move feature to test feature
kderusso 078285f Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso 66cdd3d Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso 54989ab Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso b3b2507 Ensure interception happens only once
kderusso 1c696d0 Rename InterceptedQueryBuilderWrapper to AbstractQueryBuilderWrapper
kderusso b09e1d0 Add lenient field to SemanticQueryBuilder
kderusso 916eb73 Clean up yaml test
kderusso 83ce34f Add TODO comment
kderusso 78d7b59 Add comment
kderusso 680c7d9 Spotless
kderusso 021d592 Rename AbstractQueryBuilderWrapper back to InterceptedQueryBuilderWra…
kderusso cfa288a Spotless
kderusso ba6890d Didn't mean to commit that
kderusso 1e75ab8 Remove static class wrapping the InterceptedQueryBuilderWrapper
kderusso f6b5ab5 Make InterceptedQueryBuilderWrapper part of QueryRewriteInterceptor
kderusso c998f1c Refactor the interceptor to be an internal plugin that cannot be used…
kderusso 3c59e61 Fix tests
kderusso 6c600b9 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso b7fd486 Spotless
kderusso 52babac Minor cleanup
kderusso 68f8e47 C'mon spotless
kderusso bd511b8 Test spotless
kderusso 068c4bb Cleanup InternalQueryRewriter
kderusso 7383ac6 Change if statement to assert
kderusso 08aadec Simplify template of InterceptedQueryBuilderWrapper
kderusso 77a775b Change constructor of InterceptedQueryBuilderWrapper
kderusso 21d859f Refactor InterceptedQueryBuilderWrapper to extend QueryBuilder
kderusso e52625b Cleanup
kderusso 24dc240 Add test
kderusso 53bce75 Spotless
kderusso fa17a73 Merge from main
kderusso af4cc21 Rename rewrite to interceptAndRewrite in QueryRewriteInterceptor
kderusso 2830b2d DOESN'T WORK - for testing
kderusso 7bc830a Add comment
kderusso 0d6ad3b Getting closer - match on single typed fields works now
kderusso a4d2030 Deleted line by mistake
kderusso 7dfa0a2 Checkstyle
kderusso b6b7ab4 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso a989a19 Fix over-aggressive IntelliJ Refactor/Rename
kderusso c3913ac And another one
kderusso cc6fe01 Move SemanticMatchQueryRewriteInterceptor.SEMANTIC_MATCH_QUERY_REWRIT…
kderusso 6a92936 PR feedback
kderusso f4c26ae Require query name with no default
kderusso 5d13449 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso f20a353 PR feedback & update test
kderusso 3e3cb2e Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso 278e860 Add rewrite test
kderusso 1fc6125 Update server/src/main/java/org/elasticsearch/index/query/InnerHitCon…
kderusso f6f57bb Update test
kderusso c0092e8 Merge branch 'main' into kderusso/semantic-text-match-query-support
kderusso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 117839 | ||
| summary: Add match support for `semantic_text` fields | ||
| area: "Search" | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions 110 server/src/main/java/org/elasticsearch/index/query/InterceptedQueryBuilderWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
| | ||
| package org.elasticsearch.index.query; | ||
| | ||
| import org.apache.lucene.search.Query; | ||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.plugins.internal.rewriter.QueryRewriteInterceptor; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
| | ||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
| | ||
| /** | ||
| * Wrapper for instances of {@link QueryBuilder} that have been intercepted using the {@link QueryRewriteInterceptor} to | ||
| * break out of the rewrite phase. These instances are unwrapped on serialization. | ||
| */ | ||
| class InterceptedQueryBuilderWrapper implements QueryBuilder { | ||
| | ||
| protected final QueryBuilder queryBuilder; | ||
| | ||
| InterceptedQueryBuilderWrapper(QueryBuilder queryBuilder) { | ||
| super(); | ||
| this.queryBuilder = queryBuilder; | ||
| } | ||
| | ||
| @Override | ||
| public QueryBuilder rewrite(QueryRewriteContext queryRewriteContext) throws IOException { | ||
| QueryRewriteInterceptor queryRewriteInterceptor = queryRewriteContext.getQueryRewriteInterceptor(); | ||
| try { | ||
| queryRewriteContext.setQueryRewriteInterceptor(null); | ||
| QueryBuilder rewritten = queryBuilder.rewrite(queryRewriteContext); | ||
| if (rewritten != queryBuilder) { | ||
| return new InterceptedQueryBuilderWrapper(rewritten); | ||
| } | ||
| return this; | ||
kderusso marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| } finally { | ||
| queryRewriteContext.setQueryRewriteInterceptor(queryRewriteInterceptor); | ||
| } | ||
| } | ||
| | ||
| @Override | ||
| public String getWriteableName() { | ||
| return queryBuilder.getWriteableName(); | ||
| } | ||
| | ||
| @Override | ||
| public TransportVersion getMinimalSupportedVersion() { | ||
| return queryBuilder.getMinimalSupportedVersion(); | ||
| } | ||
| | ||
| @Override | ||
| public Query toQuery(SearchExecutionContext context) throws IOException { | ||
| return queryBuilder.toQuery(context); | ||
| } | ||
| | ||
| @Override | ||
| public QueryBuilder queryName(String queryName) { | ||
| return queryBuilder.queryName(queryName); | ||
kderusso marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| } | ||
| | ||
| @Override | ||
| public String queryName() { | ||
| return queryBuilder.queryName(); | ||
| } | ||
| | ||
| @Override | ||
| public float boost() { | ||
| return queryBuilder.boost(); | ||
| } | ||
| | ||
| @Override | ||
| public QueryBuilder boost(float boost) { | ||
| return queryBuilder.boost(boost); | ||
kderusso marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| } | ||
| | ||
| @Override | ||
| public String getName() { | ||
| return queryBuilder.getName(); | ||
| } | ||
| | ||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| queryBuilder.writeTo(out); | ||
| } | ||
| | ||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| return queryBuilder.toXContent(builder, params); | ||
| } | ||
| | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o instanceof InterceptedQueryBuilderWrapper == false) return false; | ||
| return Objects.equals(queryBuilder, ((InterceptedQueryBuilderWrapper) o).queryBuilder); | ||
| } | ||
| | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(queryBuilder); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.