使用NEST显示弹性搜索命中值 [英] Display elastic search hits values using NEST
本文介绍了使用NEST显示弹性搜索命中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码来搜索文章和控件字段。它将保存2个字段的值。但是我无法访问这两个字段值。
HERE search<>是动态的。
I am using following code for searching the articleid and control fields. it will hold the 2 fields values. But I can't access these two fields values. HERE search<> is dynamic.
var searchrange = _client.Search<dynamic>(s => s
.Indices("kb_v2").Types("kb")
.From(0).Size(10)
.Fields("articleid","control")
.Query(q => q
.Range(r =>r
.OnField("articleid")
.Greater("2")
.Lower("5"))));
你可以解释如何获取这两个字段的值..
can you explain How to get the this two fields values..
推荐答案
由于Elasticsearch 1.0字段总是作为字典返回,因此字符串< string,object []>
在NEST中访问这些,您可以使用:
Since Elasticsearch 1.0 fields are always returned as a Dictionary<string, object[]>
on hits to access these in NEST you can use:
foreach (var doc in queryResults.FieldSelections)
{
var articleIds = doc.FieldValues<int[]>("articleid");
}
请参阅这个PR 有关语法的更多细节。
See this PR for more details on the syntax.
这篇关于使用NEST显示弹性搜索命中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文