es的六种搜索方式
query string search
GET /ecommerce/product/_search //查询所有数据
{
"took": 4,//耗费几毫秒
"timed_out": false,//是否超时
"_shards": {//数据拆分成5个分片,对所有请求都会打到所有primary shared(或者是它的某个replica shared也可以)
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,//条数
"max_score": 1,//查询匹配度
"hits": [
{
"_index": "ecommerce",
"_type": "product",
"_id": "2",
"_score": 1,
"_source": {
"name": "jiajieshi yagao",
"desc": "jiajieshi meibai",
"price": 30,
"producer": "jiajieshi producer",
"tags": [
"meibai",
"fangzhu"
]
}
}
]
}
}
GET /ecommerce/product/_search?q=name:yagao&sort=price:desc
query DSL
DSL:Domain Specified Language:特定领域的语言
http request body:请求体,用json格式构建查询语法
GET /ecommerce/product/_search
{
"query": {
"match": {
"name": "yagao" //查询包含单词
}
},
"_source": ["name","price"],//不写查询所有字段
"sort": [
{
"price": {
"order": "desc"//倒序排序
}
}
],
"from": 0,//分页
"size": 1
}
query filter
GET /ecommerce/product/_search
{
"query": {
"bool": {//多个条件
"must": [
{
"match": {
"name": "yagao"
}
}
],
"filter": {//过滤条件
"range": {
"price": {
"gte": 10,
"lte": 40
}
}
}
}
}
}
full-text search
GET /ecommerce/product/_search
{
"query": {
"matc