# How to get term\_vector for a document

**URL:** <https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410>\
**Category:** Elasticsearch\
**Created:** [September 19, 2011, 11:41pm UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410 "2011-09-19T23:41:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coady](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Coady](https://discuss.elastic.co/u/Coady)\
**Post date:** [September 19, 2011, 11:41pm UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/1 "2011-09-19T23:41:23Z")

</div>

Is it possible to fetch the term vector for a document through the  
API? I'd like to use the term statistics in the index to build a  
weighted query profile. The TermFreqVector per doc would be ideal,  
but also helpful would be the rewritten query from a more\_like\_this  
search and the total docFreq per term.

---

<div class="post-metadata">

**Author:** ![Loco\_Jay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loco_jay/32/2982_2.png) [@Loco\_Jay](https://discuss.elastic.co/u/Loco_Jay)\
**Post date:** [September 19, 2011, 11:46pm UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/2 "2011-09-19T23:46:32Z")

</div>

had the same question today. just have a look at

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

this works for the complete index, subset(search) or per doc  
On Sep 19, 2011, at 7:41 PM, Coady wrote:

> Is it possible to fetch the term vector for a document through the  
> API? I'd like to use the term statistics in the index to build a  
> weighted query profile. The TermFreqVector per doc would be ideal,  
> but also helpful would be the rewritten query from a more\_like\_this  
> search and the total docFreq per term.

---

<div class="post-metadata">

**Author:** ![Coady](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Coady](https://discuss.elastic.co/u/Coady)\
**Post date:** [September 20, 2011, 12:37am UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/3 "2011-09-20T00:37:51Z")

</div>

Interesting... facets are technically the inverse of the term vectors  
(doc freqs per term vs. term freqs per doc). But I see what you  
mean. I can at least start with the total index doc freqs as well as  
the terms per doc (all with a count of 1) . Thx.

On Sep 19, 4:46 pm, Loco Jay [locojay...@gmail.com](mailto:locojay...@gmail.com) wrote:

> had the same question today. just have a look at
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/)
> 
> this works for the complete index, subset(search) or per doc  
> On Sep 19, 2011, at 7:41 PM, Coady wrote:
> 
> > Is it possible to fetch the term vector for a document through the  
> > API? I'd like to use the term statistics in the index to build a  
> > weighted query profile. The TermFreqVector per doc would be ideal,  
> > but also helpful would be the rewritten query from a more\_like\_this  
> > search and the total docFreq per term.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 20, 2011, 8:39am UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/4 "2011-09-20T08:39:44Z")

</div>

There is no option to get the term vectors, but what are you after  
specifically? Is it build your own query (custom Lucene query)? In this  
case, one can do it by writing a plugin that does that (and also add it as  
part of the query DSL). If thats the case, we can help in doing that.

-shay.banon

On Tue, Sep 20, 2011 at 3:37 AM, Coady [aric.coady@gmail.com](mailto:aric.coady@gmail.com) wrote:

> Interesting... facets are technically the inverse of the term vectors  
> (doc freqs per term vs. term freqs per doc). But I see what you  
> mean. I can at least start with the total index doc freqs as well as  
> the terms per doc (all with a count of 1) . Thx.
> 
> On Sep 19, 4:46 pm, Loco Jay [locojay...@gmail.com](mailto:locojay...@gmail.com) wrote:
> 
> > had the same question today. just have a look at
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/)
> > 
> > this works for the complete index, subset(search) or per doc  
> > On Sep 19, 2011, at 7:41 PM, Coady wrote:
> > 
> > > Is it possible to fetch the term vector for a document through the  
> > > API? I'd like to use the term statistics in the index to build a  
> > > weighted query profile. The TermFreqVector per doc would be ideal,  
> > > but also helpful would be the rewritten query from a more\_like\_this  
> > > search and the total docFreq per term.

---

<div class="post-metadata">

**Author:** ![Coady](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Coady](https://discuss.elastic.co/u/Coady)\
**Post date:** [September 20, 2011, 10:32pm UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/5 "2011-09-20T22:32:23Z")

</div>

Yes, I'm looking to build a custom query based on user preferences,  
e.g., like or dislikes of documents in the index. Mathematically it  
would analogous to a more\_like\_this query, except those are only based  
on a single doc at a time.

A plugin may work, but I'd rather not recompute the custom query per  
request. If I was using raw lucene, I would pull the the term\_vector  
for each relevant doc and do a weighted version of what the  
more\_like\_this expansion does.

On Sep 20, 1:39 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> There is no option to get the term vectors, but what are you after  
> specifically? Is it build your own query (custom Lucene query)? In this  
> case, one can do it by writing a plugin that does that (and also add it as  
> part of the query DSL). If thats the case, we can help in doing that.
> 
> -shay.banon
> 
> On Tue, Sep 20, 2011 at 3:37 AM, Coady [aric.co...@gmail.com](mailto:aric.co...@gmail.com) wrote:
> 
> > Interesting... facets are technically the inverse of the term vectors  
> > (doc freqs per term vs. term freqs per doc). But I see what you  
> > mean. I can at least start with the total index doc freqs as well as  
> > the terms per doc (all with a count of 1) . Thx.
> 
> > On Sep 19, 4:46 pm, Loco Jay [locojay...@gmail.com](mailto:locojay...@gmail.com) wrote:
> > 
> > > had the same question today. just have a look at
> 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/)
> 
> > > this works for the complete index, subset(search) or per doc  
> > > On Sep 19, 2011, at 7:41 PM, Coady wrote:
> 
> > > > Is it possible to fetch the term vector for a document through the  
> > > > API? I'd like to use the term statistics in the index to build a  
> > > > weighted query profile. The TermFreqVector per doc would be ideal,  
> > > > but also helpful would be the rewritten query from a more\_like\_this  
> > > > search and the total docFreq per term.

---

<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:53am UTC](https://discuss.elastic.co/t/how-to-get-term-vector-for-a-document/5410/6 "2017-07-06T03:53:59Z")

</div>


