Hi Guys,
earlier, I have used elastic 5.7 version in my application for the elastic search feature and used Nest lib in C# to get search results. Recently, upgraded Elastic version to 6.7, similarly, I have updated the relevant C# Code. But, facing issue while reading Script field values and it does not allow me access Value from it.
var remainders = topHits.Hits().Select(x => x.Fields).First().ToList();
var d = ((LazyDocument)remainders[0].Value);
it has field value type as LazyDocument and it does not have the option to read a value from it.
var client = new ElasticClient();
var searchResponse = client.Search<object>(s => s
.Source(false)
.ScriptFields(sf => sf
.ScriptField("commentMultiplier", sd => sd
.Source("doc['commentCount'].value * params.factor")
.Params(d => d
.Add("factor", 3)
)
)
)
);
// gather a collection of document id and commentMultiplier tuples
var idsAndcommentMultipliers = searchResponse.Hits.Select(h =>
{
var id = h.Id;
// Script fields always return an array, so get first value for each document
var commentMultiplier = h.Fields["commentMultiplier"].As<int[]>().First();
return (id, commentMultiplier);
}).ToList();
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.