-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Fix bug in rule_query that resulted in errors when performing text_ex… #105311
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
Fix bug in rule_query that resulted in errors when performing text_ex… #105311
Conversation
…pansion queries. Clean up the rule_query logic to be a bit simpler to read.
Hi @kderusso, I've created a changelog YAML for you. |
} | ||
|
||
@Override | ||
public void testCacheability() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had to be overwritten to avoid throwing indoToQuery
Pinging @elastic/ent-search-eng (Team:Enterprise Search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment regarding the cleanup. Can you open a separate pr and focus this one on fixing the bug? That should also simplify the backport.
} | ||
|
||
public RuleQueryBuilder(StreamInput in) throws IOException { | ||
super(in); | ||
organicQuery = in.readNamedWriteable(QueryBuilder.class); | ||
matchCriteria = in.readGenericMap(); | ||
rulesetId = in.readString(); | ||
pinnedIds = in.readOptionalStringCollectionAsList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be removed without a backward compatibility check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀️ Thanks for the catch!
if (pinnedDocsSupplier != null) { | ||
throw new IllegalStateException("pinnedDocsSupplier must be null, can't serialize suppliers, missing a rewriteAndFetch?"); | ||
} | ||
|
||
out.writeNamedWriteable(organicQuery); | ||
out.writeGenericMap(matchCriteria); | ||
out.writeString(rulesetId); | ||
out.writeOptionalStringCollection(pinnedIds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach looks good to me, but I will abstain from approving pending resolution of @jimczi's comments
@@ -13,23 +13,16 @@ | |||
import static org.elasticsearch.xpack.searchbusinessrules.PinnedQueryBuilder.Item; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to your changes, but do you think the name Item
still fits our purposes? My guess is that when we added the pinned query, we did not think this class will get reused, so having it called Item
has not an issue.
But now when I see Item
referenced outside of the pinned query, I have to stop and think where that comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. Item
is nice because it's short, but PinnedDocument
would probably be a better name in retrospect since Document
would be too overloaded. Or PinnedDoc
if we thought PinnedDocument
was way too long.
I'd be open to a quick rename PR as a followup.
Query rules has a bug where a
rule_query
with an underlying organictext_expansion
query will fail with the reason"failed to create query: text_expansion should have been rewritten to another query type"
.The reason for this is that the
text_expansion
query will throw this as it expects to be rewritten as a boolean query of weighted tokens. However, when we change it to a pinned query during the rewrite phase, it never gets re-written again when the pinned query tries to generate a query.I also did some cleanup in this PR to simplify pinned documents - previously we allowed a list of String ids or Item documents specifying an index and an id. Since we now support documents with a null index that behave the same as a String id we can simplify the logic to determine what needs to be pinned.
Here's an example script to test the functionality. It requires an index pipeline set up using ELSER on a field called
text
.