# MultTermVectors in Elasticsearch Java

**URL:** <https://discuss.elastic.co/t/multtermvectors-in-elasticsearch-java/53953>\
**Category:** Elasticsearch\
**Created:** [June 26, 2016, 3:30am UTC](https://discuss.elastic.co/t/multtermvectors-in-elasticsearch-java/53953 "2016-06-26T03:30:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [June 26, 2016, 3:30am UTC](https://discuss.elastic.co/t/multtermvectors-in-elasticsearch-java/53953/1 "2016-06-26T03:30:32Z")

</div>

I am using the following function to get the term vector for some set of IDs.

```
public static void builtTermVectorRequest(Client client, String index, Map<String, String> postIDs) {
    TermVectorsRequest termVectorsRequest = new TermVectorsRequest();
    termVectorsRequest.index(index).type("post");
    for (Map.Entry<String, String> entry : postIDs.entrySet()) {
      String currentPostId = entry.getKey();
      String currentParentID = entry.getValue();
      termVectorsRequest
              .id(currentPostId)
              .parent(currentParentID)
              .termStatistics(true)
              .selectedFields("content");
    }

    MultiTermVectorsRequestBuilder mtbuilder = client.prepareMultiTermVectors();
    mtbuilder.add(termVectorsRequest);

    MultiTermVectorsResponse response = mtbuilder.execute().actionGet();
    XContentBuilder builder;
    try {
      builder = XContentFactory.jsonBuilder().startObject();
      response.toXContent(builder, ToXContent.EMPTY_PARAMS);
      builder.endObject();
      System.out.println(builder.prettyPrint().string());
    } catch (IOException e) {}
  }

```

Here I have some document IDs along with their parent IDs as the documents are child documents.

I get that the documents were not found even when they exist.

To confirm I tried the same thing in Python using:

```
body = dict(docs=map(lambda x:
                     {
                         "fields": ["content"],
                         "_id": x["_id"],
                         "_routing": x["_routing"],
                         "term_statistics": "true"
                     }, result["hits"]["hits"]))

es_client = elasticsearch.Elasticsearch([{'host': '192.168.111.12', 'port': 9200}])

all_term_vectors = es_client.mtermvectors(
    index="prf_test",
    doc_type="post",
    body=body
)

```

and I get results back.

What is wrong with the Java code?

---

<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 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/multtermvectors-in-elasticsearch-java/53953/2 "2017-07-05T22:40:28Z")

</div>


