《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.3.Search通过Kibana(4) https://developer.aliyun.com/article/1231067
定制化返回参数
只获取 _source 部分参数,类似数据库查询中的指定字段,而不是 select * 返回所有字段:
#GET 请求模式 GET my_goods/_source/1/?_source_includes=brandName,goodsName #返回 { "brandName" : "苹果", "goodsName" : "苹果 51英寸 4K超高清" } #POST body 请求模式 POST my_goods/_search { "query": { "match_all": { } }, "fields": ["brandName", "goodsName"], "_source": false } #返回 "hits" : [ { "_index" : "my_goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0, "fields" : { "brandName" : [ "苹果" ], "goodsName" : [ "苹果 55英寸 3K超高清" ] } }, { "_index" : "my_goods", "_type" : "_doc", "_id" : "3", "_score" : 1.0, "fields" : { "brandName" : [ "美国苹果" ], "goodsName" : [ "苹果UA55RU7520JXXZ 53英寸 4K高清" ] } }, ... }
查询文档 ID 为 1 的文档是否存在。
只判断文档是否存在 ,Head 返回的信息更少、性能更高,满足特殊业务场景使用:
HEAD /my_goods/_doc/1
返回:
200 - OK
Mutil get
Elasticsearch 同时支持批量查询,需要使用 _mget API,查询文档 ID 等于1和2的文档信息:
GET /my_goods/_mget { "docs": [ { "_id": "1" }, { "_id": "2" } ] }
返回:
{ "docs" : [ { "_index" : "my_goods", "_type" : "_doc", "_id" : "1", "_version" : 7, "_seq_no" : 8, "_primary_term" : 1, "found" : true, "_source" : { "goodsName" : "苹果 51英寸 4K超高清", "skuCode" : "skuCode1", "brandName" : "苹果", "closeUserCode" : [ "0" ], "channelType" : "cloudPlatform", "shopCode" : "sc00001", "publicPrice" : "8188.88", "groupPrice" : null, "boxPrice" : null, "boostValue" : 1.8, "shopName" : "张三店铺" } }, { "_index" : "my_goods", "_type" : "_doc", "_id" : "2", "found" : false } ] }
《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.3.Search通过Kibana(6) https://developer.aliyun.com/article/1231065