URL 查询
示例:
GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s
{
"profile":"true"
}
语法解释:
- q 指定查询语句,实验Query String Syntax
- df 默认字段,不指定时,会对所有字段进行查询
- Sort 排序 /from 和size 用于分页
- profile 可以查看查询如何被执行的
查询示例
GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s
{
"profile": "true"
}
GET /_cat/indices
GET /movies/_search?q=title:"Beautiful Mind"
{
"profile": "true"
}
GET /movies/_search?q=title:Beautiful Mind
{
"profile": "true"
}
GET /movies/_search?q=title:(Beautiful Mind)
{
"profile": "true"
}
GET /movies/_search?q=title:(Beautiful AND Mind)
{
"profile": "true"
}
GET /movies/_search?q=title:(Beautiful %2BMind)
{
"profile": "true"
}
// 范围查询 区间表示 []闭区间{} 开区间
GET /movies/_search?q=year:{1980 TO 2000]
{
"profile": "true"
}
// 算术符号
GET /movies/_search?q=year:>1980
{
"profile": "true"
}
// 通配符查询(通配符查询效率低,占用内存大,不建议使用,特别是放在最前面)
GET /movies/_search?q=title:b*
{
"profile": "true"
}
// 正则表达式查询
GET /movies/_search?q=title:[bt]oy
{
"profile": "true"
}
// 模糊查询 用户单词输出情况的时候模糊匹配
GET /movies/_search?q=title:beautifl~1
{
"profile": "true"
}
// 模糊查询 用户单词输出情况的时候模糊匹配
GET /movies/_search?q=title:"Lord Rings"~2
{
"profile": "true"
}
Request Body Search
// Request Body Search
// 对日期进行排序
GET /kibana_sample_data_ecommerce/_search
{
"sort":[{"order_date":"desc"}],
"query": {
"match_all": {}
}
}
// 对source 过滤
GET /kibana_sample_data_ecommerce/_search
{
"_source":["order_date"],
"query": {
"match_all": {}
}
}
// 脚本字段
GET /kibana_sample_data_ecommerce/_search
{
"script_fields": {
"new_field": {
"script": {
"lang": "painless",
"source": "doc['order_date'].value+'_hello'"
}
}
},
"query": {
"match_all": {}
}
}
// 短语搜索 Match Phrase
// or 查询
POST movies/_search
{
"query": {
"match": {
"title": "Last Christmas"
}
}
}
// 查询包含Last Christms title
POST movies/_search
{
"query": {
"match": {
"title": {
"query": "Last Christmas",
"operator": "and"
}
}
}
}
// slop 查询 代表中间可以有其它字符进入
POST movies/_search
{
"query": {
"match_phrase": {
"title": {
"query": "one love",
"slop": 1
}
}
}
}