ES的多种检索方式
查询全部:
GET /ecommerce/product/_search
took:1 #耗费了多少毫秒
time_out:false #是否超时
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
}
"hits.total":6 查询结果的数量
"max_score" : 1.0 score的含义,就是document对于一个search的相关度的匹配分数,越相关,就越匹配,分数越高
"hits.hits":包含了匹配搜索的document的详细数据
GET /ecommerce/product/_search?q=name:yagao&sort=price:desc
DSL(Domain Specified Language):特定领域的语言
1.查询所有的商品
GET /ecommerce/product/_search
{
"query":{
"match_all":{}
}
}
2.降序排序
GET /ecommerce/product/_search
{
"query":{
"match":{
"name":"yagao"
}
},
"sort":[
{"price":"desc"}
]
}
3.分页查询
GET /ecommerce/product/_search
{
"query":{
"match_all":{}
},
"from":1,
"size":2
}
4.指定查询输出的字段
GET /ecommerce/product/_search
{
"query":{
"match_all":{}
},
"_source":["name","price"]
}
}
5.对数据进行过滤
GET /ecommerce/product/_search
{
"query":{
"bool":{
"must":{
"match":{
"name":"yagao"
}
},
"filter":{
"range":{
"price":{
"gt":11
}
}
}
}
}
}
6.全文检索
GET /ecommerce/product/_search
{
"query":{
"match":{
"producer":"yagao producer"
}
}
}
7.短语搜索
GET /ecommerce/product/_search
{
"query":{
"match_phrase":{
"producer":"yaogao producer"
}
}
}
8.高亮
GET /ecommerce/product/_search
{
"query":{
"match_phrase":{
"producer":"yaogao producer"
}
},
"highlight":{
"fields":{
"producer":{}
}
}
}