Skip to content

Commit db1a149

Browse files
committed
Cluster loaded successfully
1 parent daa528e commit db1a149

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRules.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import org.elasticsearch.plugins.Plugin;
1111
import org.elasticsearch.plugins.SearchPlugin;
12+
import org.elasticsearch.xcontent.ParseField;
13+
import org.elasticsearch.xpack.searchbusinessrules.PinnedQueryBuilder;
14+
import org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder;
1215

1316
import java.util.List;
1417

@@ -21,4 +24,11 @@ public List<QuerySpec<?>> getQueries() {
2124
return singletonList(new QuerySpec<>(PinnedQueryBuilder.NAME, PinnedQueryBuilder::new, PinnedQueryBuilder::fromXContent));
2225
}
2326

27+
@Override
28+
public List<RetrieverSpec<?>> getRetrievers() {
29+
return singletonList(new RetrieverSpec<>(
30+
new ParseField(PinnedRetrieverBuilder.NAME),
31+
PinnedRetrieverBuilder::fromXContent
32+
));
33+
}
2434
}

x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/retriever/PinnedRetrieverBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ private void validateIdsAndDocs(List<String> ids, List<SpecifiedDocument> docs)
8989
}
9090

9191
private void validateSort(SearchSourceBuilder source) {
92+
// Allow null or empty sort, or sort only containing _score
9293
List<SortBuilder<?>> sorts = source.sorts();
93-
if (sorts != null && sorts.stream().anyMatch(sort -> sort instanceof ScoreSortBuilder == false)) {
94-
throw new IllegalArgumentException("Pinned retriever only supports sorting by score. Custom sorting is not allowed.");
94+
if (sorts != null && sorts.isEmpty() == false) {
95+
// Check if there's any sort other than ScoreSortBuilder
96+
if (sorts.stream().anyMatch(sort -> sort instanceof ScoreSortBuilder == false)) {
97+
throw new IllegalArgumentException("Pinned retriever only supports sorting by score. Custom sorting is not allowed.");
98+
}
9599
}
100+
// If sorts is null, empty, or only contains ScoreSortBuilder, it's valid.
96101
}
97102

98103
public PinnedRetrieverBuilder(List<String> ids, List<SpecifiedDocument> docs, RetrieverBuilder retrieverBuilder, int rankWindowSize) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRules

x-pack/plugin/search-business-rules/src/yamlRestTest/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesClientYamlTestSuiteIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
44

5+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
6+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
57
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
68
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
9+
import org.junit.ClassRule;
710

811
public class SearchBusinessRulesClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
912

13+
@ClassRule
14+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
15+
.distribution(DistributionType.DEFAULT)
16+
.setting("xpack.license.self_generated.type", "trial")
17+
.setting("xpack.security.enabled", "false")
18+
.build();
19+
1020
public SearchBusinessRulesClientYamlTestSuiteIT(final ClientYamlTestCandidate testCandidate) {
1121
super(testCandidate);
1222
}
@@ -15,4 +25,9 @@ public SearchBusinessRulesClientYamlTestSuiteIT(final ClientYamlTestCandidate te
1525
public static Iterable<Object[]> parameters() throws Exception {
1626
return ESClientYamlSuiteTestCase.createParameters();
1727
}
28+
29+
@Override
30+
protected String getTestRestCluster() {
31+
return cluster.getHttpAddresses();
32+
}
1833
}

x-pack/plugin/search-business-rules/src/yamlRestTest/resources/rest-api-spec/test/search-business-rules/10_pinned_retriever.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ setup:
400400
---
401401
"pinned retriever error cases":
402402
- do:
403-
catch: /\[pinned\] duplicate id found in list: doc1/
403+
catch: '/\[pinned\] duplicate id found in list: doc1/'
404404
search:
405405
index: test-index1
406406
body:
@@ -413,7 +413,7 @@ setup:
413413
match_all: {}
414414

415415
- do:
416-
catch: /\[pinned\] Cannot specify both ids and docs parameters/
416+
catch: '/\[pinned\] Cannot specify both ids and docs parameters/'
417417
search:
418418
index: test-index1
419419
body:

0 commit comments

Comments
 (0)