版权声明:转载需附上本文地址 https://blog.csdn.net/weikaixxxxxx/article/details/86476624
工具
:postman
搜索的地址
http://192.168.247.140:9200/test/test/_search
查询的数据
es基本使用的是json格式进行条件查询的
一个词
{
"query": {
"match": {
"name": "充气"
}
}
}
url版,不需要json体
http://192.168.247.140:9200/test/test/_search?q=name:充气
q=
:是必须的。
name
:是字段。
:
:是必须的。
充气
:是要搜索的词。
多个词,中间加空格也行
{
"query": {
"match": {
"name": "充气真人"
}
}
}
多字段查询
{
"query": {
"bool": {
"should": [
{ "match": { "name": "充气" }},
{ "match": { "price": "1333" }}
]
}
}
}
多字段查询权重,越重要的数据排越前
{
"query": {
"bool": {
"should": [
{ "match": {
"name": {
"query": "充气",
"boost": 1
}}},
{ "match": {
"price": {
"query": "1333",
"boost": 2
}}}
]
}
}
}
boost数字越高权重越高。
扫描二维码关注公众号,回复:
5647021 查看本文章
返回多少条
http://192.168.247.140:9200/test/test/_search?size=2
size
:返回几条数据,像sql的limit
分页
http://192.168.247.140:9200/test/test/_search?size=2&from=2
from
:忽略最前面的多少条数据。
执行分页搜索,可查看id是否重复了。
可见,七条数据都分页成功了。
每一页返回多少数据的数字都应该和忽略多少数据的相同。
并且查询,直接发送请求,无需加json
http://192.168.247.140:9200/test/test/_search?q=%2Bname%3A硅胶+%2Bprice%3A1333
%2Bname%3A硅胶
:表示name字段的硅胶。
%2Bprice%3A1333
:表示price字段的1333。
+
:必须要满足我们的查询匹配条件,不是连接符,有特殊意义。
为什么要加2B和3A?我也不知道!反正去掉就不行。
聚合查询,右侧的会延迟出现,需要等。
里面有些不能用,因为这个文档是基于2.x版的,我们现在用的都到6了。