In Solr and ES this is done with faceting and aggregations, respectively, based on Lucene's low-level APIs. Have you looked at TermsEnum? You can use that to get all distinct terms for a segment, and then it is up to you to coalesce terms across segments ("leaves").
On Thu, Nov 21, 2019 at 1:15 AM Amol Suryawanshi <amol.suryawan...@qualitiasoft.com> wrote: > > Hello, > > I am using lucene in my organization. I want to know how can I get distinct > values from lucene index. I have tried “GroupingSearch” API but it doesn’t > serves the purpose. It will give all documents contains distinct values. I > have used below code. > > > final GroupingSearch groupingSearch = new GroupingSearch(groupField); > > Sort sort = new Sort(new SortField(groupField, SortField.Type.STRING_VAL, > false)); > groupingSearch.setSortWithinGroup(sort); > Query query = new MatchAllDocsQuery(); > TopGroups<BytesRef> topGroups = null; > > try { > topGroups = groupingSearch.search(searcher, query, 0, 10); > } catch (final IOException e) { > System.out.println("Can't execute group search because of an IOException. > "+ e); > } > > Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10 > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org