**Build scan:**
https://gradle-enterprise.elastic.co/s/7vcre2by7feoe/tests/:server:internalClusterTest/org.elasticsearch.search.aggregations.bucket.SignificantTermsSignificanceScoreIT/testScriptScore

**Reproduction line:**
```
./gradlew ':server:internalClusterTest' --tests "org.elasticsearch.search.aggregations.bucket.SignificantTermsSignificanceScoreIT.testScriptScore" -Dtests.seed=3AF8B75C5D0AD4EA -Dtests.locale=es-PR -Dtests.timezone=EAT -Druntime.java=20
```

**Applicable branches:**
main

**Reproduces locally?:**
Yes

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.search.aggregations.bucket.SignificantTermsSignificanceScoreIT&tests.test=testScriptScore

**Failure excerpt:**
```
java.lang.Exception: Test abandoned because suite timeout was reached.

  at __randomizedtesting.SeedInfo.seed([3AF8B75C5D0AD4EA]:0)

```
server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/SignificanceLookup.java
}
    private long getBackgroundFrequency(Query query) throws IOException {
        
        if (query instanceof TermQuery) {
            
            
            Term term = ((TermQuery) query).getTerm();
            TermsEnum termsEnum = getTermsEnum(term.field());
            if (termsEnum.seekExact(term.bytes())) {
                return termsEnum.docFreq();
            }
            return 0;
        }
        
        if (backgroundFilter != null) {
            query = new BooleanQuery.Builder().add(query, Occur.FILTER).add(backgroundFilter, Occur.FILTER).build();
        }
        return context.searcher().count(query);
    }
    private TermsEnum getTermsEnum(String field) throws IOException {
        
        if (termsEnum != null) {
            return termsEnum;
        }
        IndexReader reader = context.searcher().getIndexReader();
        termsEnum = new FilterableTermsEnum(reader, fieldType.name(), PostingsEnum.NONE, backgroundFilter);
        return termsEnum;
    }
}