# Facet query sorted by tf\*idf

**URL:** <https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466>\
**Category:** Elasticsearch\
**Created:** [October 25, 2012, 5:48am UTC](https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466 "2012-10-25T05:48:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Rode1](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@Chris\_Rode1](https://discuss.elastic.co/u/Chris_Rode1)\
**Post date:** [October 25, 2012, 5:48am UTC](https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466/1 "2012-10-25T05:48:55Z")

</div>

Hi All

We need a way to get all terms in a document set sorted by tf\*idf. I have  
been looking at ways of getting this data in the most efficient way  
possible and I thought I would simply post here to see if elasticsearch  
allows you to do something like that

Essentially it would be a facet search sorted by tf\*idf descending, so I  
could get the highest scoring terms first

Else is there a way to get the idf score for a term from ElasticSearch so  
that I can calculate the tf\*idf score myself? Perhaps  
using [http://www.elasticsearch.org/guide/reference/api/explain.html](http://www.elasticsearch.org/guide/reference/api/explain.html)?

Cheers for your help

Chris

--

---

<div class="post-metadata">

**Author:** ![Ferdy\_Galema](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Ferdy\_Galema](https://discuss.elastic.co/u/Ferdy_Galema)\
**Post date:** [November 15, 2012, 7:03am UTC](https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466/2 "2012-11-15T07:03:52Z")

</div>

Hi Chris,

Did you by any chance have any progress on this? This is exactly what I  
need too.

Cheers.

On Thursday, October 25, 2012 7:48:55 AM UTC+2, Chris Rode wrote:

> Hi All
> 
> We need a way to get all terms in a document set sorted by tf\*idf. I have  
> been looking at ways of getting this data in the most efficient way  
> possible and I thought I would simply post here to see if elasticsearch  
> allows you to do something like that
> 
> Essentially it would be a facet search sorted by tf\*idf descending, so I  
> could get the highest scoring terms first
> 
> Else is there a way to get the idf score for a term from Elasticsearch so  
> that I can calculate the tf\*idf score myself? Perhaps using  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/explain.html)?
> 
> Cheers for your help
> 
> Chris

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [November 15, 2012, 9:28pm UTC](https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466/3 "2012-11-15T21:28:52Z")

</div>

I'm not the original Chris but I do have some thoughts on the issue,

The original need sounds like it's more related to term vectors than to  
facets, but Elasticsearch does not expose term vectors out-of-box. If you  
felt comfortable writing some Java code you could write your own plugin  
which accessed them and returned them.

Alternatively if you want to pursue the facet approach, you'll still need  
to write a plugin (but a less complex one) which introduces a custom  
FacetCollector and computes the information for each term.

Both approaches require using the Lucene API a little but are very doable.

On Thursday, November 15, 2012 8:03:52 PM UTC+13, Ferdy Galema wrote:

> Hi Chris,
> 
> Did you by any chance have any progress on this? This is exactly what I  
> need too.
> 
> Cheers.
> 
> On Thursday, October 25, 2012 7:48:55 AM UTC+2, Chris Rode wrote:
> 
> > Hi All
> > 
> > We need a way to get all terms in a document set sorted by tf\*idf. I have  
> > been looking at ways of getting this data in the most efficient way  
> > possible and I thought I would simply post here to see if elasticsearch  
> > allows you to do something like that
> > 
> > Essentially it would be a facet search sorted by tf\*idf descending, so I  
> > could get the highest scoring terms first
> > 
> > Else is there a way to get the idf score for a term from Elasticsearch so  
> > that I can calculate the tf\*idf score myself? Perhaps using  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/explain.html)?
> > 
> > Cheers for your help
> > 
> > Chris

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:04am UTC](https://discuss.elastic.co/t/facet-query-sorted-by-tf-idf/9466/4 "2017-07-06T03:04:04Z")

</div>


