目录
- 一、初始化文档数据
- 二、指定查询字段查询文档
- 2.1、概述
- 2.2、示例
一、初始化文档数据
-
在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/1,请求体内容为:
{"name":"张三","age":22,"sex":"男" }
-
在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/2,请求体内容为:
{"name":"张三1","age":22,"sex":"男" }
-
在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/3,请求体内容为:
{"name":"李四","age":23,"sex":"女" }
-
在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/4,请求体内容为:
{"name":"李四1","age":24,"sex":"女" }
二、指定查询字段查询文档
2.1、概述
- 默认情况下,Elasticsearch 在搜索的结果中,会把文档中保存在_source 的所有字段都返回。
如果我们只想获取其中的部分字段,我们可以添加_source 的过滤。
2.2、示例
-
在 Postman 中,向 ES 服务器发 GET请求 :http://localhost:9200/user/_search,请求体内容为:
{"_source": ["name","sex"],"query": {"terms": {"sex": ["男"]}} }
-
服务器响应结果