# Accessing terms in TermVectorResponse

**URL:** <https://discuss.elastic.co/t/accessing-terms-in-termvectorresponse/127555>\
**Category:** Elasticsearch\
**Created:** [April 10, 2018, 11:14pm UTC](https://discuss.elastic.co/t/accessing-terms-in-termvectorresponse/127555 "2018-04-10T23:14:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdeck51](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@sdeck51](https://discuss.elastic.co/u/sdeck51)\
**Post date:** [April 10, 2018, 11:14pm UTC](https://discuss.elastic.co/t/accessing-terms-in-termvectorresponse/127555/1 "2018-04-10T23:14:43Z")

</div>

Hello,

I'm trying to get a list of Terms from a termvectorresponse in an elasticsearch plugin. I want to get access to all of the statistics which are tied to the terms and am having trouble figuring out how to do that.

After making a TermVectorsRequest...

```
TermVectorsRequest tvReq = new TermVectorsRequest(request.param("index"), request.param("type"), request.param("id"));
tvReq.termStatistics(true);
tvReq.selectedFields(request.param("field"));

```

and getting a response from the client...

```
TermVectorsResponse tvResponse = client.termVectors(tvReq).get();

```

I can get access to the id, index, etc. In the fields I get "contents" which is the field name that I want. From there though it looks like I can run...

```
tvResponse.getFields().terms("some term here")

```

in which the Terms object this returns has access to the stats I want.

I have a few issues with this though. One is that only "contents" seems to be non null. If I run the \_termvectors endpoint with term stats turned on in kibana I get a slew of terms

```
{
  "_index": "computervectors",
  "_type": "doc",
  "_id": "1",
  "_version": 1,
  "found": true,
  "took": 4,
  "term_vectors": {
"contents": {
  "terms": {
    "5": {
      "doc_freq": 75,
      "ttf": 118,
      "term_freq": 1
    },
    "13": {
      "doc_freq": 20,
      "ttf": 28,
      "term_freq": 1
    },
    "14": {
      "doc_freq": 20,
      "ttf": 25,
      "term_freq": 1
    },
    "20": {
      "doc_freq": 50,
      "ttf": 66,
      "term_freq": 1
    },
    "25": {
      "doc_freq": 34,
      "ttf": 49,
      "term_freq": 1
    },
    "1988": {
      "doc_freq": 31,
      "ttf": 35,
      "term_freq": 1
    },...

```

Any of these terms I try don't seem to work.

Two, is I want to get a list of terms rather than having to type in which term I want.

How can I go about doing this?

Thanks

---

<div class="post-metadata">

**Author:** ![sdeck51](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@sdeck51](https://discuss.elastic.co/u/sdeck51)\
**Post date:** [April 11, 2018, 5:03pm UTC](https://discuss.elastic.co/t/accessing-terms-in-termvectorresponse/127555/4 "2018-04-11T17:03:16Z")

</div>

I've figured it out. Had to access the iterator, and then everything else I was able to figure out via lucene documentation. This can be closed.

---

<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:** [May 9, 2018, 5:03pm UTC](https://discuss.elastic.co/t/accessing-terms-in-termvectorresponse/127555/5 "2018-05-09T17:03:32Z")

</div>

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