Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
84b6ed7
Created PinnedQueryRetriever Builder
mridula-s109 Apr 7, 2025
4c6f284
Added retriever build test file
mridula-s109 Apr 7, 2025
18bf6e4
Changed the test to accept all the retrievers as its not licensed
mridula-s109 Apr 7, 2025
8bab3d2
[CI] Auto commit changes from spotless
Apr 7, 2025
2cfcdc1
Added integration test and fixed the code style issues
mridula-s109 Apr 7, 2025
760415d
Fixed merge issues
mridula-s109 Apr 7, 2025
9bc751a
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 7, 2025
63ac692
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 8, 2025
eec5f60
Added cluster test feature to the integration tests
mridula-s109 Apr 8, 2025
69e14cc
Update docs/changelog/126401.yaml
mridula-s109 Apr 8, 2025
626ebac
Registered retriever plugin
mridula-s109 Apr 8, 2025
c724b75
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 9, 2025
ef5f50f
Enhanced changelog description
mridula-s109 Apr 9, 2025
721b1d1
Added validation to the constructor creation
mridula-s109 Apr 9, 2025
a75926c
Introduced validations in the code and incorporated in tests - compil…
mridula-s109 Apr 10, 2025
c84028e
Included PinnedRankDoc to enhance the explain query, validations for …
mridula-s109 Apr 10, 2025
38e8d06
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 10, 2025
4476564
Working on improving integration test and introducing cluster features
mridula-s109 Apr 10, 2025
eaee938
Removed cluster test temporarily
mridula-s109 Apr 10, 2025
2aad145
Got pinnedretriever yaml to working state without cluster
mridula-s109 Apr 10, 2025
08e5add
[CI] Auto commit changes from spotless
Apr 10, 2025
daa528e
Resolved no source yaml error
mridula-s109 Apr 11, 2025
db1a149
Cluster loaded successfully
mridula-s109 Apr 11, 2025
e00c249
[CI] Auto commit changes from spotless
Apr 14, 2025
c659c1c
Fixed integration test
mridula-s109 Apr 14, 2025
7ab4b76
Made validate sort less strict
mridula-s109 Apr 14, 2025
e1a4362
Included shareddoc sorting in the validate sort
mridula-s109 Apr 14, 2025
3e40f6e
All yaml issues resolved
mridula-s109 Apr 14, 2025
1d4eb6f
Explanation yaml files added
mridula-s109 Apr 14, 2025
05a05a0
Trying to add clustering to the test
mridula-s109 Apr 14, 2025
e2fc29b
[CI] Auto commit changes from spotless
Apr 14, 2025
dc02f53
Removed explicit feature specification
mridula-s109 Apr 14, 2025
e2b8cb6
Deleted the empty file
mridula-s109 Apr 14, 2025
aefc0c6
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 14, 2025
f621af0
Put the node feature in the proper place
mridula-s109 Apr 15, 2025
a3de636
Added additional validation in ids and docs
mridula-s109 Apr 15, 2025
5626dd7
Cleaned the create pinned query validation
mridula-s109 Apr 15, 2025
f19b718
made unit tests robust
mridula-s109 Apr 16, 2025
7e90b88
Remove query.es from version control
mridula-s109 Apr 16, 2025
923e154
Remove result.json from version control
mridula-s109 Apr 16, 2025
583324b
[CI] Auto commit changes from spotless
Apr 16, 2025
aebe17a
Everything except explanation is fixed
mridula-s109 Apr 16, 2025
455db59
added duplicate doc test
mridula-s109 Apr 16, 2025
c5ff33d
Applied checkstyle fix, spotless and a failing yaml
mridula-s109 Apr 16, 2025
ba40533
Improvements based on PR comments
mridula-s109 Apr 16, 2025
4456504
[CI] Auto commit changes from spotless
Apr 16, 2025
3c86416
Modified the unit test to accomodate the change in createPinnedQuery
mridula-s109 Apr 16, 2025
f2035a6
Split the yaml to test for basic and trial, cleanedup and acted on al…
mridula-s109 Apr 16, 2025
516ed7c
Remove result.json and query.es from version control
mridula-s109 Apr 16, 2025
97c3376
Removed unnecessary comments
mridula-s109 Apr 16, 2025
ebbf1af
Removed redundant file
mridula-s109 Apr 16, 2025
dada60f
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 16, 2025
9b30e87
Fixing CI build error
mridula-s109 Apr 17, 2025
095eac1
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 17, 2025
374b37d
[CI] Auto commit changes from spotless
Apr 17, 2025
42dc070
Removed pinnedBy as it wasnt necessary
mridula-s109 Apr 23, 2025
d869c9e
Removed unnecessary ToXContent Information
mridula-s109 Apr 23, 2025
d67b291
Fixed transport version charges and cleaned up null checks:
mridula-s109 Apr 23, 2025
1c239d4
[CI] Auto commit changes from spotless
Apr 23, 2025
38c5dbf
Retriever status changed to 9.1 version
mridula-s109 Apr 23, 2025
40cd06b
cleaned up 2 yamltestsuite for different licenses
mridula-s109 Apr 23, 2025
8d3a36b
Trying to get the clustering works
mridula-s109 Apr 24, 2025
f63c78d
Cleaned up the yaml clustering and also reorganised the yaml tests
mridula-s109 Apr 24, 2025
e13f93e
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 24, 2025
2f1c377
Unnecessary file introduction removed
mridula-s109 Apr 24, 2025
c979859
Reverted the plugins to the previous state as the changes werent nece…
mridula-s109 Apr 24, 2025
527a9bf
Removed unnecessary transport versioning from pinnedrankdoc
mridula-s109 Apr 24, 2025
42e5973
reverted
mridula-s109 Apr 24, 2025
f9ed13a
[CI] Auto commit changes from spotless
Apr 24, 2025
1aa42f8
Edited the SearchBusinessRules to remove the class from getFeatures
mridula-s109 Apr 25, 2025
92993d0
[CI] Auto commit changes from spotless
Apr 25, 2025
018a525
Cleaned up Pinned retriever to allow only id or docs
mridula-s109 Apr 25, 2025
137cc0d
Added more test to the pinned retriever
mridula-s109 Apr 25, 2025
1525069
did spotless
mridula-s109 Apr 25, 2025
0449bc6
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 25, 2025
74f7a95
Introduced new transport versioning
mridula-s109 Apr 25, 2025
dea8d6c
Cleaning it up
mridula-s109 Apr 28, 2025
5d6575a
Resolved validate module error
mridula-s109 Apr 28, 2025
9bed922
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 28, 2025
63a16db
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 28, 2025
fae7a05
BWT issues
mridula-s109 Apr 28, 2025
4c4dee6
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 28, 2025
5b5ede4
[CI] Auto commit changes from spotless
Apr 28, 2025
215523d
fix NPE occuring in ci
mridula-s109 Apr 28, 2025
27a33a0
trying to fix duplicate feature issue
mridula-s109 Apr 29, 2025
4c8b701
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 29, 2025
4cfcbad
[CI] Auto commit changes from spotless
Apr 29, 2025
13f80fb
modified the tests
mridula-s109 Apr 29, 2025
2bfcb81
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 29, 2025
247c78d
Playing with pinned retriever CI (#127530)
kderusso Apr 30, 2025
e86c6e0
Merge branch 'main' into pinned-retriever
mridula-s109 Apr 30, 2025
cbb8ab1
top document no pinned
mridula-s109 Apr 30, 2025
9bfcb4b
Removing this to see if it works without this transport version check…
mridula-s109 Apr 30, 2025
227011b
Fixed the retriever builder comments and error message
mridula-s109 Apr 30, 2025
84608c0
removed the unnencessary explain
mridula-s109 Apr 30, 2025
1a68442
Fixed all the tests in the yaml file
mridula-s109 Apr 30, 2025
29d16a2
added extra test case
mridula-s109 Apr 30, 2025
71c3439
merged main
mridula-s109 Apr 30, 2025
819e279
[CI] Auto commit changes from spotless
Apr 30, 2025
bd29ce8
Merge branch 'main' into pinned-retriever
mridula-s109 May 1, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/126401.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 126401
summary: Add pinned retriever
area: Relevance
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ static TransportVersion def(int id) {
public static final TransportVersion INTRODUCE_FAILURES_LIFECYCLE = def(9_065_0_00);
public static final TransportVersion PROJECT_METADATA_SETTINGS = def(9_066_00_0);
public static final TransportVersion AGGREGATE_METRIC_DOUBLE_BLOCK = def(9_067_00_0);
public static final TransportVersion PINNED_RETRIEVER = def(9_068_0_00);
Copy link
Contributor

Choose a reason for hiding this comment

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

just a side note - but when we backport this to 8.19, we need to pay extra attention on how we backport this transport version

Copy link
Member

Choose a reason for hiding this comment

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

Yeah @mridula-s109 - we will create a PINNED_RETRIEVER_8_19 transport version


/*
* STOP! READ THIS FIRST! No, really,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugin/ent-search/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ esplugin {
name = 'x-pack-ent-search'
description = 'Elasticsearch Expanded Pack Plugin - Enterprise Search'
classname = 'org.elasticsearch.xpack.application.EnterpriseSearch'
extendedPlugins = ['x-pack-core']
extendedPlugins = ['x-pack-core', 'search-business-rules']
}

base {
Expand All @@ -17,7 +17,7 @@ base {

dependencies {
compileOnly project(path: xpackModule('core'))
implementation project(xpackModule('search-business-rules'))
compileOnly project(xpackModule('search-business-rules'))
api project(':modules:lang-mustache')

// JSON Schema dependencies
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/rank-rrf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
clusterModules project(xpackModule('rank-rrf'))
clusterModules project(xpackModule('inference'))
clusterModules project(':modules:lang-painless')
clusterModules project(xpackModule('search-business-rules'))

clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
setup:
- requires:
cluster_features: 'pinned_retriever_supported'
reason: 'test requires pinned retriever implementation'
- do:
indices.create:
index: test-index1

- do:
bulk:
refresh: true
index: test-index1
body:
- index:
_id: doc1
- { "text": "document one" }
- index:
_id: doc2
- { "text": "document two" }
- index:
_id: doc3
- { "text": "document three" }
- index:
_id: doc4
- { "text": "document four" }
- index:
_id: doc5
- { "text": "document five" }

---
"rrf combined with pinned retriever":
- skip: { features: headers }
- do:
headers:
Content-Type: application/json
search:
index: test-index1
body:
retriever:
pinned:
ids: ["doc1"]
retriever:
rrf:
retrievers: [
{
standard: {
query: {
term: { text: "document" }
}
}
},
{
standard: {
query: {
term: { text: "three" }
}
}
}
]
rank_window_size: 10

- match: { hits.total.value: 5 }
- match: { hits.hits.0._id: doc1 }
- match: { hits.hits.0._score: 1.7014122E38 }
- match: { hits.hits.1._id: doc3 }
- match: { hits.hits.1._score < 100.0 }
- match: { hits.hits.2._id: doc2 }

---
"rrf with pinned retriever as a sub-retriever":
- skip: { features: headers }
- do:
headers: { Content-Type: application/json }
search:
index: test-index1
body:
retriever:
rrf:
retrievers:
-
standard:
query:
match: { text: "document" }
-
pinned:
ids: ["doc4", "doc5"]
retriever:
standard:
query:
match: { text: "document" }

- match: { hits.total.value: 5 }
- match: { hits.hits.0._id: doc1 }
- lt: { hits.hits.0._score: 100.0 }
- match: { hits.hits.1._id: doc4 }
- match: { hits.hits.2._id: doc5 }


16 changes: 15 additions & 1 deletion x-pack/plugin/search-business-rules/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

esplugin {
name = 'search-business-rules'
Expand All @@ -13,6 +14,19 @@ base {

dependencies {
compileOnly project(path: xpackModule('core'))
compileOnly project(':server')
testImplementation(testArtifact(project(xpackModule('core'))))
testImplementation project(":test:framework")
testImplementation(testArtifact(project(':server')))
clusterModules project(xpackModule('search-business-rules'))
clusterModules project(':modules:mapper-extras')
clusterModules project(':modules:lang-painless')
clusterModules project(xpackModule('inference'))
}

tasks.named("yamlRestTest") {
usesDefaultDistribution("uses search business rules plugin")
}
artifacts {
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
requires org.elasticsearch.xcore;

exports org.elasticsearch.xpack.searchbusinessrules;

provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRulesFeatures;
provides org.elasticsearch.plugins.SearchPlugin with org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRules;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class PinnedQueryBuilder extends AbstractQueryBuilder<PinnedQueryBuilder>

// Organic queries will have their scores capped to this number range,
// We reserve the highest float exponent for scores of pinned queries
private static final float MAX_ORGANIC_SCORE = Float.intBitsToFloat((0xfe << 23)) - 1;
public static final float MAX_ORGANIC_SCORE = Float.intBitsToFloat((0xfe << 23)) - 1;

public PinnedQueryBuilder(QueryBuilder organicQuery, String... ids) {
this(organicQuery, Arrays.asList(ids), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@

package org.elasticsearch.xpack.searchbusinessrules;

import org.elasticsearch.plugins.ExtensiblePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.plugins.SearchPlugin.QuerySpec;
import org.elasticsearch.plugins.SearchPlugin.RetrieverSpec;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder;

import java.util.List;

import static java.util.Collections.singletonList;

public class SearchBusinessRules extends Plugin implements SearchPlugin {
public class SearchBusinessRules extends Plugin implements SearchPlugin, ExtensiblePlugin {

@Override
public List<QuerySpec<?>> getQueries() {
return singletonList(new QuerySpec<>(PinnedQueryBuilder.NAME, PinnedQueryBuilder::new, PinnedQueryBuilder::fromXContent));
return List.of(new QuerySpec<>(PinnedQueryBuilder.NAME, PinnedQueryBuilder::new, PinnedQueryBuilder::fromXContent));
}

@Override
public List<RetrieverSpec<?>> getRetrievers() {
return singletonList(new RetrieverSpec<>(new ParseField(PinnedRetrieverBuilder.NAME), PinnedRetrieverBuilder::fromXContent));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.searchbusinessrules;

import org.elasticsearch.features.FeatureSpecification;
import org.elasticsearch.features.NodeFeature;

import java.util.Set;

import static org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder.PINNED_RETRIEVER_FEATURE;

public class SearchBusinessRulesFeatures implements FeatureSpecification {

@Override
public Set<NodeFeature> getFeatures() {
return Set.of();
}

@Override
public Set<NodeFeature> getTestFeatures() {
return Set.of(PINNED_RETRIEVER_FEATURE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.endObject();
}

static final ConstructingObjectParser<SpecifiedDocument, Void> PARSER = new ConstructingObjectParser<>(
public static final ConstructingObjectParser<SpecifiedDocument, Void> PARSER = new ConstructingObjectParser<>(
NAME,
a -> new SpecifiedDocument((String) a[0], (String) a[1])
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.searchbusinessrules.retriever;

import org.apache.lucene.search.Explanation;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.rank.RankDoc;

import java.io.IOException;
import java.util.Objects;

public class PinnedRankDoc extends RankDoc {
public static final String NAME = "pinned_rank_doc";

private final boolean isPinned;

public PinnedRankDoc(int docId, float score, int shardIndex, boolean isPinned) {
super(docId, score, shardIndex);
this.isPinned = isPinned;
}

public PinnedRankDoc(StreamInput in) throws IOException {
super(in);
this.isPinned = in.readBoolean();
}

public boolean isPinned() {
return isPinned;
}

@Override
public Explanation explain(Explanation[] sources, String[] queryNames) {
if (isPinned) {
return Explanation.match(score, "Pinned document, original explanation:", sources);
} else {
return super.explain(sources, queryNames);
}
}

@Override
public String toString() {
return super.toString() + ", isPinned=" + isPinned;
}

@Override
public String getWriteableName() {
return NAME;
}

@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeBoolean(isPinned);
}

@Override
protected boolean doEquals(RankDoc rd) {
if (rd instanceof PinnedRankDoc other) {
return this.isPinned == other.isPinned;
} else {
return false;
}
}

@Override
protected int doHashCode() {
return Objects.hash(super.doHashCode(), isPinned);
}

@Override
public TransportVersion getMinimalSupportedVersion() {
return TransportVersions.PINNED_RETRIEVER;
}
}
Loading
Loading