{"record":{"id":"7eddadb6aed04e28","repo":"languagetool-org/languagetool","slug":"no-field-fieldname-found-in-doc-match","errorCode":null,"errorMessage":"No field '\" + fieldName + \"' found in doc + match.doc","messagePattern":"No field '\" \\+ fieldName \\+ \"' found in doc \\+ match\\.doc","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java","lineNumber":280,"sourceCode":"    } else {\n      throw new PatternRuleNotFoundException(ruleId, language);\n    }\n  }\n\n  private MatchingSentencesResult findMatchingSentences(IndexSearcher indexSearcher, TopDocs topDocs, JLanguageTool languageTool) throws IOException {\n    List<MatchingSentence> matchingSentences = new ArrayList<>();\n    int i = 0;\n    int docsChecked = 0;\n    for (ScoreDoc match : topDocs.scoreDocs) {\n      i++;\n      if (i < skipHits) {\n        // needed for paging\n        continue;\n      }\n      Document doc = indexSearcher.doc(match.doc);\n      String sentence = doc.get(fieldName);\n      if (sentence == null) {\n        throw new RuntimeException(\"No field '\" + fieldName + \"' found in doc \" + match.doc);\n      }\n      List<RuleMatch> ruleMatches = languageTool.check(sentence);\n      docsChecked++;\n      if (ruleMatches.size() > 0) {\n        String source = doc.get(SOURCE_FIELD_NAME);\n        String title = doc.get(Indexer.TITLE_FIELD_NAME);\n        AnalyzedSentence analyzedSentence = languageTool.getAnalyzedSentence(sentence);\n        MatchingSentence matchingSentence = new MatchingSentence(sentence, source, title, analyzedSentence, ruleMatches);\n        matchingSentences.add(matchingSentence);\n      }\n    }\n    return new MatchingSentencesResult(matchingSentences, i, docsChecked);\n  }\n  \n  static class MatchingSentencesResult {\n    List<MatchingSentence> matchingSentences;\n    int maxDocChecked;\n    int docsChecked;","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java#L262-L298","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nthrow new RuntimeException(\"No field '\" + fieldName + \"' found in doc \" + match.doc);\n// after\nif (sentence == null) { LOG.warn(\"doc \" + match.doc + \" missing field \" + fieldName); continue; }","handlingStrategy":"validation","validationCode":"Document doc = indexSearcher.doc(match.doc);\nif (doc.get(fieldName) == null) { skip; }","typeGuard":null,"tryCatchPattern":"try {\n  result = searcher.findMatchingSentences(...);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"No field\")) { rebuildIndex(); }\n}","preventionTips":["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"],"tags":["lucene","index","missing-field"],"backgroundTag":"resource-not-found","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}