以下查询样例均在
ES 5.6.1
版本进行
下载样例数据
1
https://github.com/Witee/statics/blob/master/blog/elasticsearch/example-data/accounts.json
写入 ES
自动创建了索引
bank
,类型account
,使用bulk
接口批量操作1
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
查看索引
1
curl 'localhost:9200/_cat/indices?v'
普通查询
- 匹配所有;
- 按
account_number
升序; - 从第 3 条记录开始(注意这里的
from
不表示页码); - 每页显示 2 条;
1
2
3
4
5
6
7
8
9
10{
"query": {
"match_all": {}
},
"sort": {
"account_number": {"order": "asc"}
},
"from": 3,
"size": 2
}sort
可以写多条1
2
3
4"sort": [
{"balance": {"order": "desc"} },
{"account_number": {"order": "asc"} }
]_source
中指定返回字段1
"_source": ["account_number", "balance"]
match
会对查询关键词先进行分词,再查询
address
包含 mill
或 lane
,不区分大小写
1 | { |
address
包含 mill
且 lane
,不区分大小写
1 | { |