很抱歉重复出现问题,但这似乎不适用于当前的Elastic Search 2.x版本。基本上,我使用NEST向ES发送查询,并希望以纯JSON格式获取响应,就像在Sense上使用POST命令一样。这里存在类似的问题:Returning Raw Json in ElasticSearch NEST query
使用以下方法检索的结果:
var searchResult = _elasticClient.LowLevel.Search<SearchResponse<SearchResult>>(querytEST);
想要的结果:
{
"took": 406,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 14,
"max_score": 0,
"hits": []
},
"aggregations": {
"query": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1,
"buckets": [
{
"key": "laura",
"doc_count": 14,
"top": {
"hits": {
"total": 14,
"max_score": 4.1078563,
"hits": [
{...
最佳答案
传递给底层客户端上的T
的.Search<T>
类型指定结果的返回类型。为了获取json,您只需将其更改为string
var searchResult = _elasticClient.LowLevel.Search<string>(querytEST);
关于serialization - 将 Elasticsearch 结果返回为原始JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40133890/