Hi, I found the solution:
builder.startObject(); termVectorResponse.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); You have to first create an object in the builder. Cheers, KLaus On Monday, February 23, 2015 at 1:57:29 PM UTC+1, Klausen Schaefersinho wrote: > > Hi, > > > I am trying to get the term vector for an document in Java. The problem is, > that the call returns an object where the realy payload is not accessible > through the API. Therefore I was now trying to go around and use the > toXContent() method and generate a josn and use this to acess the data. > However the JSON String generated by the XContentBuilder is not valid. Before > valid json comes, I have some not valid string like _id, _type etc. It seems > the meatinfo is somehow prefixed to the real json. How can I solve this issue? > > > Here is an example of the returned json: > > > > "_index""content","_type" "content","_id" > "http://www.page.com/a/1.html","_version" > 1,"found" true,"term_vectors" > {"main":{"field_statistics":{"sum_doc_freq":4,"doc_count":1,"sum_ttf":4},"terms":{"döner":{"doc_freq":1,"ttf":1,"term_freq":1,"tokens":[{"position":3,"start_offset":16,"end_offset":21,"payload":"PEFMUEhBTlVNPg=="}]},"einen":{"doc_freq":1,"ttf":1,"term_freq":1,"tokens":[{"position":2,"start_offset":10,"end_offset":15,"payload":"PEFMUEhBTlVNPg=="}]},"ist":{"doc_freq":1,"ttf":1,"term_freq":1,"tokens":[{"position":1,"start_offset":6,"end_offset":9,"payload":"PEFMUEhBTlVNPg=="}]},"klaus":{"doc_freq":1,"ttf":1,"term_freq":1,"tokens":[{"position":0,"start_offset":0,"end_offset":5,"payload":"PEFMUEhBTlVNPg=="}]}}} > > > > And here is my code: > > > > final TermVectorResponse termVectorResponse = getClient().termVector(new > TermVectorRequest() > > .index(this.index) > > .type(this.type) > > .id(id) > > .termStatistics(true) > > .selectedFields(new String[]{"main", "abs", "title"})) > > .actionGet(); > > > > XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); > > termVectorResponse.toXContent(builder, null); > > > > Cheers, > > Klaus > -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6ea5ce4d-1f30-434b-8154-9f401ec00515%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
