Skip to content

字段过滤

查询只输出某些字段

GET /user/docs/_search?_source=name,age
GET /user/docs/_search?_source=name,age

这样就会限制只显示 nameage 字段

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "王五",
          "age" : 25
        }
      },
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "王五",
          "age" : 25
        }
      }
    ]
  }
}
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "王五",
          "age" : 25
        }
      },
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "王五",
          "age" : 25
        }
      }
    ]
  }
}

备案号:冀ICP备20015584号-2