Skip to content

[8.19] Optimize sparse vector stats collection (#128740) #128771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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/128740.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 128740
summary: Optimize sparse vector stats collection
area: Stats
type: enhancement
issues: []
19 changes: 9 additions & 10 deletions server/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.index.SegmentReader;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.QueryCache;
import org.apache.lucene.search.QueryCachingPolicy;
Expand Down Expand Up @@ -61,7 +60,6 @@
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.DocumentParser;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.index.mapper.LuceneDocument;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.Mapping;
Expand Down Expand Up @@ -337,14 +335,15 @@ protected final SparseVectorStats sparseVectorStats(IndexReader indexReader, Lis

private long getSparseVectorValueCount(final LeafReader atomicReader, List<BytesRef> fields) throws IOException {
long count = 0;
Terms terms = atomicReader.terms(FieldNamesFieldMapper.NAME);
if (terms == null) {
return count;
}
TermsEnum termsEnum = terms.iterator();
for (var fieldName : fields) {
if (termsEnum.seekExact(fieldName)) {
count += termsEnum.docFreq();
for (var fieldNameBR : fields) {
var fieldName = fieldNameBR.utf8ToString();
var fi = atomicReader.getFieldInfos().fieldInfo(fieldName);
if (fi == null) {
continue;
}
Terms terms = atomicReader.terms(fieldName);
if (terms != null) {
count += terms.getDocCount();
}
}
return count;
Expand Down