serialization - 将 Elasticsearch 结果返回为原始JSON

标签 serialization elasticsearch json.net nest

很抱歉重复出现问题,但这似乎不适用于当前的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/

相关文章:

java - 自定义 BeanPropertyFilter - 仅序列化字符串的一部分

.net - 如何将派生类序列化为其基类

c++ - boost::serialization:是否可以避免使用模板函数?

python - 我该如何修复 'failed to find geo_point field [pin.location]'

c# - 为什么这个匿名类型不能使用 JsonConvert.DeserializeAnonymousType 正确反序列化?

c# - 使用 JsonConverter 序列化/反序列化各种 `Brush` 类型

powershell - 为什么这个新的JObject添加到我的字符串时会奇怪地更改它?

java - Jersey/Jackson 仅基类序列化问题

java - elasticsearchrepository 在字段中保存空值

node.js - NodeJs + PostgreSQL + ElasticSearch