[英]Display elastic search hits values using NEST
I am using following code for searching the articleid and control fields. 我正在使用以下代码搜索articleid和控件字段。 it will hold the 2 fields values.
它将保存2个字段的值。 But I can't access these two fields values.
但是我无法访问这两个字段的值。 HERE search<> is dynamic.
在这里search <>是动态的。
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.. 您能解释一下如何获取这两个字段的值吗?
Since Elasticsearch 1.0 fields are always returned as a Dictionary<string, object[]>
on hits to access these in NEST you can use: 由于Elasticsearch 1.0字段始终以
Dictionary<string, object[]>
返回,因此可以在NEST中访问它们,因此可以使用:
foreach (var doc in queryResults.FieldSelections)
{
var articleIds = doc.FieldValues<int[]>("articleid");
}
See this PR for more details on the syntax. 有关语法的更多详细信息,请参见此PR 。
The search response ( ISearchResponse
type) has a FieldSelections property which holds the results and details. 搜索响应(
ISearchResponse
类型)具有FieldSelections属性,该属性保存结果和详细信息。 With the older version of Nest, one had to loop over the Hits property to find the value of each field. 使用较旧的Nest版本,必须遍历Hits属性才能找到每个字段的值。
"hits": [
{
"_index": "kb_v2",
"_type": "kb",
"_id": "3565178",
"_score": 1,
"fields": {
"articleid": [
"3"
]
}
},
{
"_index": "kb_v2",
"_type": "kb",
"_id": "3932480",
"_score": 1,
"fields": {
"articleid": [
"4"
]
}
}]
More on how to use the FieldSelections in ElastichSearch.net client is mentioned in this Unit test here 更多关于如何使用ElastichSearch.net客户端FieldSelections在这个单元测试中提到这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.