1.query string
GET /test/_search?q=name:yagao&sort=price:desc
不建议使用,一旦查询条件过多 是很难去构建的
在生产环境中,几乎很少使用query string
- query DSL
GET /test/_search
{
“query” : {
“match” : {
“name” : “yagao”
}
},
“sort”: [
{ “price”: “desc” }
]
}
带分页查询
GET /test/_search
{
“query”: { “match_all”: {} },
“from”: 1,
“size”: 1
}
指定返回字段
GET /test/_search
{
“query”: { “match_all”: {} },
“_source”: [“name”, “price”]
}
3、query filter
搜索商品名称包含yagao,而且售价大于25元的商品
GET /test/_search
{
“query” : {
“bool” : {
“must” : {
“match” : {
“name” : “yagao”
}
},
“filter” : {
“range” : {
“price” : { “gt” : 25 }
}
}
}
}
}
4、full-text search(全文检索)
GET /test/_search
{
“query” : {
“match” : {
“producer” : “yagao producer”
}
}
}
5.phrase search(短语搜索)
搜索的字段里面必须得保函该短语分词之后的的所有词
GET /test/_search
{
“query” : {
“match_phrase” : {
“producer” : “yagao producer”
}
}
}
- highlight search(高亮搜索结果)
GET /test/_search
{
“query” : {
“match” : {
“producer” : “producer”
}
},
“highlight”: {
“fields” : {
“producer” : {}
}
}
}
