如何编写单个Elasticsearch查询,该查询将计算有多少文档具有某个字段的值或缺少该字段?

此查询成功地计算出docst 缺少的字段:

POST localhost:9200//<index_name_here>/_search
{
    "size": 0,
    "aggs" : {
        "Missing_Field" : {
            "missing": { "field": "group_doc_groupset_id" }
        }
    }
}

此查询的操作与此相反,计数文档而不缺少字段:
POST localhost:9200//<index_name_here>/_search
{
    "size": 0,
    "aggs" : {
        "Not_Missing_Field" : {
            "exists": { "field": "group_doc_groupset_id" }
        }
    }
}

我怎么写一个结合了两者的书?例如,这产生语法错误:
POST localhost:9200//<index_name_here>/_search
{
    "size": 0,
    "aggs" : {
        "Missing_Field_Or_Not" : {
            "missing": { "field": "group_doc_groupset_id" },
            "exists": { "field": "group_doc_groupset_id" }
        }
    }
}

最佳答案

GET indexname/_search?size=0
{
  "aggs": {
    "a1": {
      "missing": {
        "field": "status"
      }
    },
    "a2": {
      "filter": {
        "exists": {
          "field": "status"
        }
      }
    }
  }
}

关于elasticsearch - 在Elasticsearch中计算有多少个文档具有属性或缺少该属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37929836/

10-10 18:28
查看更多