# How to get query term vectors using scripts?

**URL:** <https://discuss.elastic.co/t/how-to-get-query-term-vectors-using-scripts/68119>\
**Category:** Elasticsearch\
**Created:** [December 6, 2016, 2:19am UTC](https://discuss.elastic.co/t/how-to-get-query-term-vectors-using-scripts/68119 "2016-12-06T02:19:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Zhang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_zhang/32/745_2.png) [@Jason\_Zhang](https://discuss.elastic.co/u/Jason_Zhang)\
**Post date:** [December 6, 2016, 2:19am UTC](https://discuss.elastic.co/t/how-to-get-query-term-vectors-using-scripts/68119/1 "2016-12-06T02:19:23Z")

</div>

I'm using scripts to implement some custom score function like:

```
∑is_ge_1(_index['FIELD']['TERM'].tf()) / my_query.termvectors('ANALYZER').size()
where TERM is one of my_query.termvectors(), and FIELD can be passed from script params.

```

I'm able to get `_index['FIELD']['TERM'].tf()` according to the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-advanced-scripting.html).

But how can I get the whole query term vectors just like `_analyzer` API?  
I've googled this before but didn't get something useful. Only lucene v3.5 has QueryTermVector API.  
Or if there's some other better approaches to implement this?

Thank you in advance.

---

<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:** [January 3, 2017, 2:19am UTC](https://discuss.elastic.co/t/how-to-get-query-term-vectors-using-scripts/68119/2 "2017-01-03T02:19:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
