官方文档
Elastic Search Query DSL的文档地址:
Query DSL
Kibana - Dev tools
查询操作DSL
GET _cat/indices
GET book/_search
{
"query": {
"match_all": {}
}
}
#此查询将文本或短语与一个或多个字段的值匹配。
GET book/_search
{
"query": {
"match": {
"saleCnt": 3000
}
}
}
#此查询精确值匹配
GET book/_search
{
"query": {
"match_phrase": {
"title" : {
"query" : "Spring data",
"slop" : 1
}
}
}
}
GET book/_search
{
"query": {
"term": {
"saleCnt": {
"value": "3000"
}
}
}
}
#此查询将文本或短语与多个字段匹配。
POST book/_search
{
"query": {
"multi_match": {
"query": "zhoudy教程",
"fields": ["title", "author"]
}
}
}
#此查询使用查询解析器和query_string关键字
POST book/_search
{
"query": {
"query_string": {
"default_field": "title",
"query": "spring AND 教程 OR ssss 教程"
}
}
}
#这些查询主要处理结构化数据,如数字,日期和枚举。
POST book/_search
{
"query": {
"term": {
"saleCnt": {
"value": "4000"
}
}
}
}
#此查询用于查找值的范围之间的值的对象
GET book/_search
{
"query": {
"range": {
"saleCnt": {
"gte": 1000,
"lte": 3000
}
}
}
}
#查询满足必须条件并添加过滤条件
GET book/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Spring" }},
{ "match": { "author": "zhoudy" }}
],
"filter": [
{ "term": { "author": "zhoudy" }},
{ "range": { "saleCnt": { "gte": "4000" }}}
]
}
}
}
#多搜索条件组合查询
GET book/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"author" : "zhoudy"
}
}
],
"should": [
{
"match": {
"title": "spring"
}
}
],
"must_not": [
{
"match": {
"title": "data"
}
}
],
"filter": {
"range": {
"saleCnt": {
"gte": 1000
}
}
}
}
},
"sort": [
{
"saleCnt": {
"order": "desc"
}
}
]
}
网友评论