Skip to content

Commit c88e288

Browse files
committed
Fix test and add comments
1 parent a6544f8 commit c88e288

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/ReplaceSourceAttributes.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ protected PhysicalPlan rule(EsSourceExec plan) {
4343
if (attr instanceof MetadataAttribute ma) {
4444
if (ma.name().equals(MetadataAttribute.SCORE)) {
4545
score = attr;
46-
} else if (isTimeSeries) {
47-
if (ma.name().equals(MetadataAttribute.TSID_FIELD)) {
48-
tsid = attr;
49-
} else if (ma.name().equals(MetadataAttribute.TIMESTAMP_FIELD)) {
50-
timestamp = attr;
51-
}
46+
} else if (isTimeSeries && ma.name().equals(MetadataAttribute.TSID_FIELD)) {
47+
tsid = attr;
5248
}
49+
} else if (attr.name().equals(MetadataAttribute.TIMESTAMP_FIELD)) {
50+
timestamp = attr;
5351
}
5452
keepIterating = score == null || (isTimeSeries && (tsid == null || timestamp == null));
5553
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,14 @@ private PhysicalPlan logicalPlanToPhysicalPlan(LogicalPlan optimizedPlan, EsqlQu
718718
final Holder<Boolean> hasScoring = new Holder<>(false);
719719

720720
if (filter != null) {
721+
// a PhysicalPlan completely transformed (no fragments) will have an EsQueryExec in it if the data comes from ES
721722
physicalPlan.forEachDown(EsQueryExec.class, esQueryExec -> {
722723
if (hasScoring.get() == false && esQueryExec.hasScoring()) {
723724
hasScoring.set(true);
724725
}
725726
});
727+
// if there is no EsQueryExec and still scoring is required, search for fragments as well where EsRelations should
728+
// know if there is scoring needed or not
726729
if (hasScoring.get() == false) {
727730
physicalPlan.forEachDown(FragmentExec.class, fragmentExec -> {
728731
fragmentExec.fragment().forEachDown(EsRelation.class, esRelation -> {
@@ -744,8 +747,8 @@ private PhysicalPlan logicalPlanToPhysicalPlan(LogicalPlan optimizedPlan, EsqlQu
744747
QueryBuilder newFilter;
745748
if (fragmentFilter != null) {
746749
newFilter = hasScoring.get()
747-
? boolQuery().filter(fragmentFilter).must(filter)
748-
: boolQuery().filter(fragmentFilter).filter(filter);
750+
? boolQuery().filter(fragmentFilter).must(filter) // a "bool" "must" does influence scoring
751+
: boolQuery().filter(fragmentFilter).filter(filter);// no scoring? then "filter" to completely disable scoring
749752
} else {
750753
newFilter = hasScoring.get() ? filter : boolQuery().filter(filter);
751754
}

0 commit comments

Comments
 (0)