Skip to content

Add Create or update query rule API call #109042

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
merged 16 commits into from
Jun 10, 2024

Conversation

kderusso
Copy link
Member

@kderusso kderusso commented May 24, 2024

Adds a new API call to create or update an individual query rule within a ruleset. If this call is made against a nonexistent ruleset the ruleset will be created.

Adds the ability to specify a priority of a query rule, which indicates the order in which it is inserted into an existing ruleset and subsequently processed.

Coming in followup PRs:

  • GET, DELETE API calls
  • More thorough yaml testing that requires GET and DELETE API calls
  • Documentation

Example API call:

PUT /_query_rules/test-ruleset/query-rule-id
{
  "type": "pinned",
  "priority": 4,
  "criteria": [
    {
      "type": "exact",
      "metadata": "query_string",
      "values": [
        "search"
      ]
    }
  ],
  "actions": {
    "ids": [
      "doc1",
      "doc4"
    ]
  }
}

@@ -0,0 +1,114 @@
setup:
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: There's not a lot of validation here. These will be fleshed out more in a followup PR when the GET and DELETE endpoints are implemented.

@kderusso kderusso force-pushed the kderusso/put-query-rule-api-call branch from 66b9b79 to ddbad4a Compare May 28, 2024 18:59
@kderusso kderusso changed the title WIP: Create or update query rule API call Add Create or update query rule API call May 28, 2024
@kderusso kderusso marked this pull request as ready for review May 28, 2024 19:04
@kderusso kderusso requested a review from a team as a code owner May 28, 2024 19:04
@kderusso kderusso requested a review from a team May 28, 2024 19:04
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label May 28, 2024
@kderusso kderusso added >enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team and removed needs:triage Requires assignment of a team area label labels May 28, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @kderusso, I've created a changelog YAML for you.

@Mikep86 Mikep86 self-requested a review May 29, 2024 17:26
@kderusso kderusso requested a review from ioanatia May 29, 2024 18:45
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.

Partial review, will finish up tomorrow :)

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.

Got a bit farther this morning, looking good!

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.

Nice work!

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.

LGTM, thanks for the iterations!

@@ -43,7 +43,7 @@ public TransportPutQueryRuleAction(
protected void doExecute(Task task, PutQueryRuleAction.Request request, ActionListener<PutQueryRuleAction.Response> listener) {
String queryRulesetId = request.queryRulesetId();
QueryRule queryRule = request.queryRule();
systemIndexService.putQueryRule(queryRulesetId, queryRule, listener.map(r -> new PutQueryRuleAction.Response(r.getResult())));
systemIndexService.putQueryRule(queryRulesetId, queryRule, ActionListener.wrap(listener::onResponse, listener::onFailure));
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumb question: how is this different than passing listener directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to do this because we're modifying the response from a DocWriteResponse to PutQueryRuleAction.Response but it's basically just wrapping it so we can change it to created for rulesets with new rules.

Copy link
Member Author

Choose a reason for hiding this comment

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

PS there is no such thing as a dumb question 😛

@kderusso kderusso merged commit ec0b573 into elastic:main Jun 10, 2024
15 checks passed
@kderusso kderusso deleted the kderusso/put-query-rule-api-call branch July 8, 2024 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants