6. elk请求body
RequestBody与QueryDSL简介¶
- 将查询语句通过HTTP requestbody发送给elasticsearch
POST /movie,404_idx/_search?ignore_unavailable=true { "profile":true, "query":{ "match_all":{} } } ignore_unavailable=true,可以忽略尝试访问不存在的索引“404_idx”导致的报错
-
翻页
"from":10, "to":20
-
排序
最好在数字型与日期型字段上排序(sort)
POST kibana_sample_data_ecommerce/_search { "sort":[{"order_date":"desc"}], "query":{ "match_all": {} } }
POST 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": {} } }
默认是OR的关系 POST movies/_search { "query": { "match": { "title": "last christmas" } } } #指定AND的关系 POST movies/_search { "query": { "match": { "title": { "query": "last christmas", "operator": "and" } } } }
POST movies/_search { "query": { "match_phrase": { "title":{ "query": "one love", "slop": 1 } } } } 不加slop代表的意思是顺序搜索one love中间不能有其他字符 加上slop代表的意思是one love在搜索的时候中间可以添加其他字符,是搜索的内容变大,
QueryString&SimpleQueryString查询¶
- QueryString
类似URI查询 POST users/_search { "query": { "query_string": { "default_field": "name", "query": "Ruan AND Yiming" } } } 分组 POST users/_search { "query": { "query_string": { "fields":["name","about"], "query": "(Ruan AND Yiming) OR (Java AND Elasticsearch)" } } }
- simple_query_string
1 会忽略错误只是支持部分语法
2 不支持AND NOT OR 会当作字符串处理
3 term直接默认是or 可以指定operator
4 支持部分逻辑
+and |OR -NOT
POST users/_search { "query": { "simple_query_string": { "query": "Ruan Yiming", "fields": ["name"], "default_operator": "AND" } } }