Skip to content
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 @@ -26,7 +26,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 @@ -65,7 +64,6 @@
import org.elasticsearch.index.codec.FieldInfosWithUsages;
import org.elasticsearch.index.codec.vectors.reflect.OffHeapByteSizeUtils;
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 @@ -385,14 +383,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);
Copy link
Member

Choose a reason for hiding this comment

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

I assume that we're confident that this won't continue to have too much I/O?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need to continue monitoring but that should help reduce the I/O since terms statistics are loaded eagerly when the reader is opened.

if (terms != null) {
count += terms.getDocCount();
}
}
return count;
Expand Down
Loading