# How to get splited tokens of query、 best matched document and those document's term vector at the same time when searching in elasticsearch

**URL:** https://discuss.elastic.co/t/how-to-get-splited-tokens-of-query-best-matched-document-and-those-documents-term-vector-at-the-same-time-when-searching-in-elasticsearch/261094
**Category:** Elasticsearch
**Created:** [January 14, 2021, 8:43am UTC](https://discuss.elastic.co/t/how-to-get-splited-tokens-of-query-best-matched-document-and-those-documents-term-vector-at-the-same-time-when-searching-in-elasticsearch/261094 "2021-01-14T08:43:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Shiwei\_Zhang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shiwei_zhang/32/82220_2.png) [@Shiwei\_Zhang](https://discuss.elastic.co/u/Shiwei_Zhang)
#### Post date: [January 14, 2021, 8:43am UTC](https://discuss.elastic.co/t/how-to-get-splited-tokens-of-query-best-matched-document-and-those-documents-term-vector-at-the-same-time-when-searching-in-elasticsearch/261094/1 "2021-01-14T08:43:56Z")

</div>

I want to recalculate the score according to the tf and idf according to the term\_vector from elasticsearch, so I need :

- query's tokens splitted by analyzer(i use ik\_max\_word) of elasticsearch
- best matched document id
- the term\_vector of best matched document

I also find the ways to get all those infos by three step：

- firstly, get best match document index from es and get document `_id` from `result['hits']['hits'][0]["_id"]`.
- secondly, get document term\_vector use :  
`curl -XGET 'http://localhost:9200/my_index/my_doc_type/best_match_index/_termvector?pretty=true'` where `best_match_index` is the `_id` in first step. according to [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html#docs-termvectors-terms-filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html#docs-termvectors-terms-filtering)
- Then, get the splitted tokens of query use es analyzer  
`curl -H "Content-Type: application/json" -XGET 'http://127.0.0.1:9200/my_index/_analyze?pretty=true' -d '{"field": "context", "text": "this is the test text"}'`. According to [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html#docs-termvectors-terms-filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html#docs-termvectors-terms-filtering)

In other words， I need three times request result from es server. Any method i get all those infos from es in one time?

thx

---

<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: [February 11, 2021, 8:44am UTC](https://discuss.elastic.co/t/how-to-get-splited-tokens-of-query-best-matched-document-and-those-documents-term-vector-at-the-same-time-when-searching-in-elasticsearch/261094/2 "2021-02-11T08:44:09Z")

</div>

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