[我正在运行ElasticSearch的示例示例,并阅读this link,该示例显示默认设置为10,000,也可以在搜索调用中更改此默认设置,如本示例所示
GET twitter/_search
{
"track_total_hits": 100,
"query": {
"match" : {
"message" : "Elasticsearch"
}
}
}
问题是,我试图在NEST上做同样的事情,但是我无法复制它。我发现的唯一相似之处仅是布尔值,而不是数字。是否可以通过NEST更改总数?
这是我尝试的代码:
var results = elasticClient.Search<MyClass>(s => s
.Query(q => q.QueryString(q2 => q2.Query(readLine)
.Fields(f => f.Field(p => p.MyField)))).TrackTotalHits(true));
ISearchRequest
强制转换为IRequest<SearchRequestParameters>
:var client = new ElasticClient();
var searchResponse = client.Search<Document>(s =>
{
IRequest<SearchRequestParameters> request = s;
request.RequestParameters.SetQueryString("track_total_hits", 1000);
return s;
});
它将作为查询字符串参数应用