Elasticsearch查询裁剪
如果source有成千上百个字段,查询的数据没法看
某些敏感字段不能随意展示
响应数据较大影响网络带宽
查看文档信息
查看ffbf索引id为123的文档信息
GET /ffbf/_doc/123返回结果
{
  "_index" : "ffbf",
  "_type" : "_doc",
  "_id" : "123",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "Monster",
    "age" : 26,
    "address" : "天安云谷xx栋xx层",
    "url" : "ffbf.top"
  }
}
只查看source信息
查看ffbf索引id为123的source信息
GET /ffbf/_source/123返回结果
{
  "name" : "Monster",
  "age" : 26,
  "address" : "天安云谷xx栋xx层",
  "url" : "ffbf.top"
}
不看source只获取元数据信息
GET /ffbf/_doc/123?_source=false返回结果
{
  "_index" : "ffbf",
  "_type" : "_doc",
  "_id" : "123",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true
}
#只查看source文档的某些字段
例如:address、age
GET /ffbf/_doc/123?_source_includes=address,age返回结果
{
  "_index" : "ffbf",
  "_type" : "_doc",
  "_id" : "123",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "address" : "天安云谷xx栋xx层",
    "age" : 26
  }
}
不包含doc文档的某些字段
例如:不包含name字段
GET /ffbf/_doc/123?_source_excludes=name返回结果
{
  "_index" : "ffbf",
  "_type" : "_doc",
  "_id" : "123",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "address" : "天安云谷xx栋xx层",
    "age" : 26,
    "url" : "ffbf.top"
  }
}
不包含source文档的某些字段
例如:不包含name字段的source数据
GET /ffbf/_source/123?_source_excludes=name返回结果
{
  "address" : "天安云谷xx栋xx层",
  "age" : 26,
  "url" : "ffbf.top"
}
同时查询条件为包含和不包含字段
查询source所有以a开头并且不是以e结尾的字段
GET /ffbf/_source/456?_source_includes=a*&_source_excludes=*e返回结果
{
  "address" : "天安云谷xx栋xx层"
}
                      
                      
                    
            
            
            
            
评论区