美文网首页
ES-Query DSL

ES-Query DSL

作者: 梦想又照进现实 | 来源:发表于2019-07-14 20:07 被阅读0次

官方文档

Elastic Search Query DSL的文档地址:
Query DSL

Kibana - Dev tools

工程源码: https://gitee.com/danni505/spring-data-es.git

查询操作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"
      }
    }
  ]
}





   

相关文章

网友评论

      本文标题:ES-Query DSL

      本文链接:https://www.haomeiwen.com/subject/yamikctx.html