2016-10-19 68 views
0

對不起重複的問題,但這似乎不適用於當前的Elastic Search 2.x版本。基本上,我使用NEST向ES發送查詢,並希望獲得像普通JSON一樣的響應,就像在Sense上使用POST命令一樣。存在類似問題在這裏:使用檢索Returning Raw Json in ElasticSearch NEST query將彈性搜索結果作爲原始JSON返回

結果:

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": [ 
       {... 

回答

1

傳遞給.Search<T>低級別客戶端上的類型T指定結果的返回類型。爲了讓json返回,您只需將其更改爲string

var searchResult = _elasticClient.LowLevel.Search<string>(querytEST);