How to use _mtermvectors endpoint in NEST C#?


(siva ramalingam) #1

In elasticsearch help at
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html
there is an _mtermvectors endpoint like this

POST /twitter/tweet/_mtermvectors
{
"ids" : ["1", "2"],
"parameters": {
"fields": [
"message"
],
"term_statistics": true
}
}

What is the corresponding call in NEST
I tried

var res = Client.MultiTermVectors(new MultiTermVectorsRequest("twitter", "tweet")
{
TermStatistics = true
});

How can i specify the ids array? Thanks for the help!


(siva ramalingam) #2

Used the lowlevel call like below if anyone needs it

string sbRequestBody = "{\"ids\":[\"1\", \"2\"],\"parameters\":{\"fields\": [\"message\"],\"term_statistics\":true}}";			
var termvecResponse =Client.LowLevel.Mtermvectors<MultiTermVectorsResponse>("twitter", "tweet", sbRequestBody);

foreach (var doc in termvecResponse.Body.Documents)
			{
				var item = doc.TermVectors["message"];

				Console.WriteLine("Document: {0}",doc.Id);
				foreach (var term in item.Terms)
				{
					Console.WriteLine("{0}: {1}", term.Key, term.Value.TermFrequency);

				}
			}

High level call:

var tvecR = client.MultiTermVectors(new MultiTermVectorsRequest("twitter", typeof(tweet))
{
    Fields = Infer.Fields<tweet>(f => f.Body), // all docs will use these fields
    Documents = idRange.Select(n => new MultiTermVectorOperation<tweet>(n)
    {
        TermStatistics = true
    })
});

(system) #3

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