from:偏移量,等价mysql offset
size:显示条数,等价mysql limit
match_all:无条件查找
POST /movies/_search
{
"from": 0,
"size": 10,
"query": {
"match_all": {}
}
}
通过 _source : [field…] 指定查询显示哪些字段
POST /movies/_search
{
"from": 0,
"size": 10,
"_source": ["title","year"],
"query": {
"match_all": {}
}
}
通过 sort 来指定按什么排序
POST /movies/_search
{
"from": 0,
"size": 10,
# 按照 年倒序,id正序排
"sort":[{"year":"desc"},{"_id":"asc"}],
"_source": ["title","year"],
"query": {
"match_all": {}
}
}
将match_all 替换成 match 进行有条件的查找
可以指定操作符
POST /movies/_search
{
"from": 0,
"size": 10,
"sort":[{"year":"desc"},{"_id":"asc"}],
"_source": ["title","year"],
"profile": "true",
"query": {
"match": {
# 查询字段
"title": {
# 查询字段值
"query": "Beautiful Mind",
# 操作,决定单词之间的关系
# and 要求顺序一致,词为 “Beautiful Mind”
# or 包含 Beautiful 或 Mind 即可
"operator": "and"
}
}
}
}
和match比较最明显的区别:
match: 不指定operator是or的关系
match_parase 不设置其它则是and的关系
POST /movies/_search
{
"from": 0,
"size": 10,
"sort":[{"year":"desc"},{"_id":"asc"}],
"_source": ["title","year"],
"profile": "true",
"query": {
"match_phrase": {
"title": {
"query": "one Love",
# title:"one love"~1"
# slop:1 允许one Love 中添加一个词补充
# 可以匹配 one I Love
"slop": 1
}
}
}
}
query 中 可以使用操作符
POST /movies/_search
{
"query":{
"query_string": {
# 查询字段
"fields": ["title"],
"query": "Beautiful AND Mind",
}
}
}
query中的 AND,OR,NOT 会被当作词,但是可以使用其它符号代替
a. + 代替 AND
b. - 代替 NOT
c. | 代替 OR
POST /movies/_search
{
"query":{
"simple_query_string": {
"query": "Beautiful +Mind",
"fields": ["title"]
}
}
}
或者通过 default_operator 指定操作符
POST /movies/_search
{
"query":{
"simple_query_string": {
"query": "Beautiful Mind",
"fields": ["title"],
"default_operator": "AND"
}
}
}