Elasticsearch查询以及聚合查询

1、条件查询 bool

must:返回的文档必须满足子句的条件,并且参与计算分值
filter:返回的文档必须满足filter子句的条件,不会参与计算分值
should:返回的文档可能满足should子句的条件。
must_nout:返回的文档必须不满足must_not定义的条件。
注意:如果一个查询既有filter又有should,那么至少包含一个should子句。

bool 查询

user 值为kimchy tag 值为tech

"query": {
   
   "bool" : {
   
        "must" : {
   
            "term" : {
    "user" : "kimchy" }
        },
        "filter": {
   
            "term" : {
    "tag" : "tech" }
        },
        "must_not" : {
   
            "range" : {
   
                "age" : {
    "from" : 10, "to" : 20 }
            }
        },
        "should" : [
            {
   "term" : {
    "tag" : "wow" }},
            {
   "term" : {
    "tag" : "elasticsearch" }}
        ]
    }

过滤不存在数据

"query": {
   
        "bool":{
   
            "filter":{
   
                "exists":{
   
                    "field":"subject" }
            }
        }   
    }

统计某个字段出现的次数

size 0 不需要返回文档数据,只需要值

  "size": 0,
   "query": {
   
        "bool":{
   
            "filter":{
   
                "exists":{
   
                    "field":"proofreadresult" }
            }
        }   
    }

返回 某个字段 ischeck值为false 的数量

"size": 0,
   "query": {
   
        "bool":{
   
            "must": [{
   "match": {
   "ischeck": "false"}}],
        }   
    }
}

"size": 0,
   "query": {
   
        "bool":{
   
            "must":  {
   "term" : {
    "ischeck" : "false" }}
        }   
    }
}

返回的数据 value 就是我们需要的数据

{
   
  "took" : 0,

你可能感兴趣的:(搜索引擎,elasticsearch,大数据)