languagetool-org/languagetool · error · RuntimeException
No field '" + fieldName + "' found in doc + match.doc
Error message
No field '" + fieldName + "' found in doc + match.doc
What it means
After fetching a hit document from the Lucene index, findMatchingSentences reads the configured field and throws a RuntimeException if the field is missing (null). The index was built without (or with an empty) value for the requested field, so sentence-level checking cannot proceed.
Source
Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java:280
} else {
throw new PatternRuleNotFoundException(ruleId, language);
}
}
private MatchingSentencesResult findMatchingSentences(IndexSearcher indexSearcher, TopDocs topDocs, JLanguageTool languageTool) throws IOException {
List<MatchingSentence> matchingSentences = new ArrayList<>();
int i = 0;
int docsChecked = 0;
for (ScoreDoc match : topDocs.scoreDocs) {
i++;
if (i < skipHits) {
// needed for paging
continue;
}
Document doc = indexSearcher.doc(match.doc);
String sentence = doc.get(fieldName);
if (sentence == null) {
throw new RuntimeException("No field '" + fieldName + "' found in doc " + match.doc);
}
List<RuleMatch> ruleMatches = languageTool.check(sentence);
docsChecked++;
if (ruleMatches.size() > 0) {
String source = doc.get(SOURCE_FIELD_NAME);
String title = doc.get(Indexer.TITLE_FIELD_NAME);
AnalyzedSentence analyzedSentence = languageTool.getAnalyzedSentence(sentence);
MatchingSentence matchingSentence = new MatchingSentence(sentence, source, title, analyzedSentence, ruleMatches);
matchingSentences.add(matchingSentence);
}
}
return new MatchingSentencesResult(matchingSentences, i, docsChecked);
}
static class MatchingSentencesResult {
List<MatchingSentence> matchingSentences;
int maxDocChecked;
int docsChecked;View on GitHub (pinned to 2e990059ce)
Solutions
- Rebuild the index so all documents contain the requested field
- Verify the fieldName argument matches the field used by Indexer during indexing
- Skip documents missing the field instead of aborting
- Check the index schema/mappings for null or empty stored fields
Example fix
// before
throw new RuntimeException("No field '" + fieldName + "' found in doc " + match.doc);
// after
if (sentence == null) { LOG.warn("doc " + match.doc + " missing field " + fieldName); continue; } Defensive patterns
Strategy: validation
Validate before calling
Document doc = indexSearcher.doc(match.doc);
if (doc.get(fieldName) == null) { skip; } Try / catch
try {
result = searcher.findMatchingSentences(...);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("No field")) { rebuildIndex(); }
} Prevention
- Rebuild indexes after changing field names in Indexer
- Use shared constants (e.g. Indexer field names) instead of string literals
- Validate a sample doc has all expected fields after indexing
When it happens
Trigger: A hit document in topDocs lacks the requested field (e.g. the sentence text field); happens when the index was created by an Indexer version/config that stored a different field name.
Common situations: Searching an index built with an older/different Indexer configuration; passing a wrong fieldName; documents skipped during indexing (e.g. empty pages) leaving the field unset.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Directory must contain at least '1grams', '2grams', and '3gr
- Expected at least '1grams', '2grams', and '3grams' sub direc
- No directories '1grams' ... '3grams' found in ${topIndexDir}
- Requested ${tokens.size()}gram but index has only up to ${ma
- Expected 'totalTokenCount' meta documents not found in 1gram
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/7eddadb6aed04e28.
Report an issue: GitHub.