Skip to content

Conversation

@mridula-s109
Copy link
Contributor

This PR introduces validation logic for query rules that require numeric comparisons to prevent storing rules that will never match. Previously, invalid numeric criteria could be silently ignored at query time, leading to unexpected behavior.

  • Added pre-validation in QueryRule.java to enforce numeric values for comparison rule types (lte, gte, lt, gt).
  • If a rule contains invalid values, the API will return an explicit validation error instead of silently accepting the rule.
  • Enhanced unit tests and YAML REST tests to verify validation errors.

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice start @mridula-s109 ! I've left some feedback, please let me know if you have questions.

@mridula-s109
Copy link
Contributor Author

Nice start @mridula-s109 ! I've left some feedback, please let me know if you have questions.

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice progress here @mridula-s109 , thanks for iterating!

I've left a couple of very minor comments.

The next thing that you'll want to do is:

  • Please update the title of this PR, to remove the Jira. It's OK to refer to the ticket number in the description (no links) but we don't want this being part of the official changelog as Jira is internal 🙂
  • Please remove this from draft state and apply the following labels:
    • v9.0.0
    • v8.18.0
    • auto-backport
    • :SearchOrg/Relevance
    • >bug

This will automatically create a backport to the appropriate branch when it is merged, so the bug fix goes into 9.0. It will also create a Changelog entry for this bug fix. Finally, it will ping the Search organization that the PR is available.

While CI failed, it looks like it failed on an unrelated change. CI will be re-run any time anything is added - so creating the changelog will run again. You may need to update from main via the button on the PR to resolve. We can't merge this PR until CI is green.

Thanks for your work on this!

@mridula-s109 mridula-s109 changed the title [SEARCH-802] Prevent Query Rule Creation with Invalid Numeric Match Criteria Prevent Query Rule Creation with Invalid Numeric Match Criteria Feb 20, 2025
@mridula-s109 mridula-s109 added v9.0.0 v8.18.0 auto-backport Automatically create backport pull requests when merged :SearchOrg/Relevance Label for the Search (solution/org) Relevance team >bug labels Feb 20, 2025
@mridula-s109 mridula-s109 marked this pull request as ready for review February 20, 2025 17:12
@mridula-s109 mridula-s109 enabled auto-merge (squash) February 20, 2025 17:12
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@mridula-s109 mridula-s109 requested a review from a team February 20, 2025 17:12
@mridula-s109 mridula-s109 requested a review from kderusso March 4, 2025 06:39
Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the iterations!

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.

Thanks for removing the logger! I have a suggestion about how to simplify the test code :)

@mridula-s109 mridula-s109 enabled auto-merge (squash) March 12, 2025 11:06
# Conflicts:
#	x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/rules/QueryRuleTests.java
@mridula-s109 mridula-s109 merged commit f6538e8 into elastic:main Mar 12, 2025
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 122823

albertzaharovits pushed a commit to albertzaharovits/elasticsearch that referenced this pull request Mar 13, 2025
…tic#122823)

* SEARCH-802 - bug fixed - Query rules allows for creation of rules with invalid match criteria

* [CI] Auto commit changes from spotless

* Worked on the comments given in the PR

* [CI] Auto commit changes from spotless

* Fixed Integration tests

* [CI] Auto commit changes from spotless

* Made changes from the PR

* Update docs/changelog/122823.yaml

* [CI] Auto commit changes from spotless

* Fixed the duplicate code issue in queryRuleTests

* Refactored code to clean it up based on PR comments

* [CI] Auto commit changes from spotless

* Logger statements were removed

* Cleaned up the QueryRule tests

* [CI] Auto commit changes from spotless

* Update x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/EnterpriseSearchModuleTestUtils.java

Co-authored-by: Mike Pellegrini <[email protected]>

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Co-authored-by: Kathleen DeRusso <[email protected]>
Co-authored-by: Mike Pellegrini <[email protected]>
@mridula-s109
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

mridula-s109 added a commit to mridula-s109/elasticsearch that referenced this pull request Mar 13, 2025
…tic#122823)

* SEARCH-802 - bug fixed - Query rules allows for creation of rules with invalid match criteria

* [CI] Auto commit changes from spotless

* Worked on the comments given in the PR

* [CI] Auto commit changes from spotless

* Fixed Integration tests

* [CI] Auto commit changes from spotless

* Made changes from the PR

* Update docs/changelog/122823.yaml

* [CI] Auto commit changes from spotless

* Fixed the duplicate code issue in queryRuleTests

* Refactored code to clean it up based on PR comments

* [CI] Auto commit changes from spotless

* Logger statements were removed

* Cleaned up the QueryRule tests

* [CI] Auto commit changes from spotless

* Update x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/EnterpriseSearchModuleTestUtils.java

Co-authored-by: Mike Pellegrini <[email protected]>

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Co-authored-by: Kathleen DeRusso <[email protected]>
Co-authored-by: Mike Pellegrini <[email protected]>
(cherry picked from commit f6538e8)

# Conflicts:
#	x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearchFeatures.java
@mridula-s109
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Mar 13, 2025
…tic#122823)

* SEARCH-802 - bug fixed - Query rules allows for creation of rules with invalid match criteria

* [CI] Auto commit changes from spotless

* Worked on the comments given in the PR

* [CI] Auto commit changes from spotless

* Fixed Integration tests

* [CI] Auto commit changes from spotless

* Made changes from the PR

* Update docs/changelog/122823.yaml

* [CI] Auto commit changes from spotless

* Fixed the duplicate code issue in queryRuleTests

* Refactored code to clean it up based on PR comments

* [CI] Auto commit changes from spotless

* Logger statements were removed

* Cleaned up the QueryRule tests

* [CI] Auto commit changes from spotless

* Update x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/EnterpriseSearchModuleTestUtils.java

Co-authored-by: Mike Pellegrini <[email protected]>

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Co-authored-by: Kathleen DeRusso <[email protected]>
Co-authored-by: Mike Pellegrini <[email protected]>
@mridula-s109 mridula-s109 self-assigned this Mar 13, 2025
mridula-s109 added a commit that referenced this pull request Mar 13, 2025
… Criteria (#122823) | Removed logger and also fixed the nitpick comments (#124650) (#124758)

* Prevent Query Rule Creation with Invalid Numeric Match Criteria (#122823)

* SEARCH-802 - bug fixed - Query rules allows for creation of rules with invalid match criteria

* [CI] Auto commit changes from spotless

* Worked on the comments given in the PR

* [CI] Auto commit changes from spotless

* Fixed Integration tests

* [CI] Auto commit changes from spotless

* Made changes from the PR

* Update docs/changelog/122823.yaml

* [CI] Auto commit changes from spotless

* Fixed the duplicate code issue in queryRuleTests

* Refactored code to clean it up based on PR comments

* [CI] Auto commit changes from spotless

* Logger statements were removed

* Cleaned up the QueryRule tests

* [CI] Auto commit changes from spotless

* Update x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/EnterpriseSearchModuleTestUtils.java

Co-authored-by: Mike Pellegrini <[email protected]>

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Co-authored-by: Kathleen DeRusso <[email protected]>
Co-authored-by: Mike Pellegrini <[email protected]>
(cherry picked from commit f6538e8)

# Conflicts:
#	x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearchFeatures.java

* Removed logger and also fixed the nitpick comments (#124650)

(cherry picked from commit 44a3ac4)

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >bug :SearchOrg/Relevance Label for the Search (solution/org) Relevance team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants