From 042c09617e8381719d1b4c362f8f1ccc49191e2c Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Wed, 21 May 2025 13:19:05 -0400 Subject: [PATCH 1/2] Fix: Add NamedWriteable for RuleQueryRankDoc (#128153) * Add NamedWriteable for QueryRule rank doc * Update test * Update docs/changelog/128153.yaml * Add multi cluster test for query rules * Commenting out code - explicitly trying to spur a test failure * [CI] Auto commit changes from spotless * Streamline test for multi cluster * Revert changes to try to break test * Fix compile error --------- Co-authored-by: elasticsearchmachine (cherry picked from commit b335c1a8ebc357d7437e03b2c85ad7e3c1942456) # Conflicts: # x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml --- docs/changelog/128153.yaml | 6 ++ .../xpack/application/EnterpriseSearch.java | 7 ++ .../entsearch/rules/40_rule_query_search.yml | 79 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 docs/changelog/128153.yaml diff --git a/docs/changelog/128153.yaml b/docs/changelog/128153.yaml new file mode 100644 index 0000000000000..fda435438ff53 --- /dev/null +++ b/docs/changelog/128153.yaml @@ -0,0 +1,6 @@ +pr: 128153 +summary: "Fix: Add `NamedWriteable` for `RuleQueryRankDoc`" +area: Relevance +type: bug +issues: + - 126071 diff --git a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearch.java b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearch.java index db6ee3a621d84..e19b149372ca5 100644 --- a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearch.java +++ b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearch.java @@ -30,6 +30,7 @@ import org.elasticsearch.plugins.SystemIndexPlugin; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; +import org.elasticsearch.search.rank.RankDoc; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xpack.application.analytics.AnalyticsTemplateRegistry; import org.elasticsearch.xpack.application.analytics.action.DeleteAnalyticsCollectionAction; @@ -179,6 +180,7 @@ import org.elasticsearch.xpack.application.rules.action.TransportPutQueryRulesetAction; import org.elasticsearch.xpack.application.rules.action.TransportTestQueryRulesetAction; import org.elasticsearch.xpack.application.rules.retriever.QueryRuleRetrieverBuilder; +import org.elasticsearch.xpack.application.rules.retriever.RuleQueryRankDoc; import org.elasticsearch.xpack.application.search.SearchApplicationIndexService; import org.elasticsearch.xpack.application.search.action.DeleteSearchApplicationAction; import org.elasticsearch.xpack.application.search.action.GetSearchApplicationAction; @@ -351,6 +353,11 @@ protected XPackLicenseState getLicenseState() { return Collections.unmodifiableList(actionHandlers); } + @Override + public List getNamedWriteables() { + return List.of(new NamedWriteableRegistry.Entry(RankDoc.class, RuleQueryRankDoc.NAME, RuleQueryRankDoc::new)); + } + @Override public List getRestHandlers( Settings settings, diff --git a/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml b/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml index 845cdb7f9ac19..e2e547769b064 100644 --- a/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml +++ b/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml @@ -893,3 +893,82 @@ teardown: - match: { hits.total.value: 2 } - match: { hits.hits.0._id: 'doc1' } - match: { hits.hits.1._id: 'doc4' } + +--- +"Multi-index search with missing documents does not error": + - requires: + cluster_features: [ "test_rule_retriever.with_indices_that_dont_return_rank_docs" ] + reason: "Fixed" + + - do: + indices.create: + index: test-index-001 + body: + settings: + index: + number_of_shards: 5 # Ensure more shards than docs + + - do: + indices.create: + index: test-index-002 + body: + settings: + index: + number_of_shards: 5 # Ensure more shards than docs + + - do: + bulk: + refresh: true + index: test-index-001 + body: + - index: + _id: 1 + - { "text": "patio" } + - index: + _id: 2 + - { "text": "catio" } + + - do: + bulk: + refresh: true + index: test-index-002 + body: + - index: + _id: 3 + - { "text": "balcony" } + - index: + _id: 4 + - { "text": "overhang" } + + - do: + query_rules.put_ruleset: + ruleset_id: catio-ruleset + body: + rules: + - rule_id: rule1 + type: pinned + criteria: + - type: exact + metadata: foo + values: [ bar ] + actions: + ids: + - '2' + + - do: + search: + index: test-index-001,test-index-002 + body: + retriever: + rule: + retriever: + standard: + query: + query_string: + query: "patio or balcony" + match_criteria: + foo: bar + ruleset_ids: catio-ruleset + + - match: { hits.total.value: 3 } + - match: { hits.hits.0._id: '2' } From 08b0badeefadd6373e47e231b2ab6e447ed26a0e Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Wed, 21 May 2025 13:47:54 -0400 Subject: [PATCH 2/2] Update 40_rule_query_search.yml Remove test that can't run in < 9.1 --- .../entsearch/rules/40_rule_query_search.yml | 79 ------------------- 1 file changed, 79 deletions(-) diff --git a/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml b/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml index e2e547769b064..845cdb7f9ac19 100644 --- a/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml +++ b/x-pack/plugin/ent-search/src/yamlRestTest/resources/rest-api-spec/test/entsearch/rules/40_rule_query_search.yml @@ -893,82 +893,3 @@ teardown: - match: { hits.total.value: 2 } - match: { hits.hits.0._id: 'doc1' } - match: { hits.hits.1._id: 'doc4' } - ---- -"Multi-index search with missing documents does not error": - - requires: - cluster_features: [ "test_rule_retriever.with_indices_that_dont_return_rank_docs" ] - reason: "Fixed" - - - do: - indices.create: - index: test-index-001 - body: - settings: - index: - number_of_shards: 5 # Ensure more shards than docs - - - do: - indices.create: - index: test-index-002 - body: - settings: - index: - number_of_shards: 5 # Ensure more shards than docs - - - do: - bulk: - refresh: true - index: test-index-001 - body: - - index: - _id: 1 - - { "text": "patio" } - - index: - _id: 2 - - { "text": "catio" } - - - do: - bulk: - refresh: true - index: test-index-002 - body: - - index: - _id: 3 - - { "text": "balcony" } - - index: - _id: 4 - - { "text": "overhang" } - - - do: - query_rules.put_ruleset: - ruleset_id: catio-ruleset - body: - rules: - - rule_id: rule1 - type: pinned - criteria: - - type: exact - metadata: foo - values: [ bar ] - actions: - ids: - - '2' - - - do: - search: - index: test-index-001,test-index-002 - body: - retriever: - rule: - retriever: - standard: - query: - query_string: - query: "patio or balcony" - match_criteria: - foo: bar - ruleset_ids: catio-ruleset - - - match: { hits.total.value: 3 } - - match: { hits.hits.0._id: '2' }