Directory indexDirectory = FSDirectory.open(new File("/home/ranger/index/1")); IndexReader indexReader = DirectoryReader.open(indexDirectory); Fields fields = MultiFields.getFields(indexReader ); IteratorfieldsIterator = fields.iterator(); while(fieldsIterator.hasNext()){ String field = fieldsIterator.next(); Terms terms = fields.terms(field); TermsEnum termsEnums = terms.iterator(null); BytesRef byteRef = null; System.out.println("field : "+ field); while((byteRef = termsEnums.next()) != null) { String term = new String(byteRef.bytes, byteRef.offset, byteRef.length); System.out.println("term is : " + term); } }
结果是:
field : ID
term is : 10000field : nameterm is : lettuce