简体   繁体   English

如何根据 Elasticsearch 中的特定字段获取非空值的计数

[英]how to get count of not-null value based on specific field in Elasticsearch

I have elastic search index and I need total count of records that one of fields ("actual_start") is not-null how can I do this?我有弹性搜索索引,我需要字段之一(“actual_start”)不为空的记录总数,我该怎么做?

I have wrote this query and I want to append count of not-null actual start value to the result of my query:我已经写了这个查询,我想将非空实际起始值的计数附加到我的查询结果中:

 $params = [
            'index' => "appointment_request",
            'body' => [
                'from' => $request['from'],
                'size' => $request['size'],
                "query" => [
                    "bool"=>[
                        "must" => [

                            [
                                "term" => [
                                    "doctor_id" => [
                                        "value" => $request['doctor_id']
                                    ]
                                ]
                            ],
                            [
                                "match" => [
                                    "book_date" => $request['book_date']

                                ]
                            ],
                      
                        ]

                    ],
                ]
            ]
        ];

Take a look at Exists Query查看Exists 查询

Try this:尝试这个:

GET <your-index>/_count
{
  "query": {
    "exists": {
      "field": "actual_start"
    }
  }
}

Then you can read the count value which will give you the total count of records that actual_start is not-null.然后您可以读取count数值,该值将为您提供actual_start不为空的记录总数。

You can also replace _count with _search and total value under hits will give you a total count (in case you also want the hits ) .您还可以将_count替换为_searchhits下的total价值将为您提供总计数(如果您还需要hits )。

If you want to do the opposite (all records which actual_start is null):如果你想做相反的事情(所有actual_start为空的记录):

GET <your-index>/_count
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "actual_start"
          }
        }
      ]
    }
  }
}

UPDATE更新

If I understand you correctly you want to append your current query with the exists query.如果我理解正确,您希望将当前查询附加到exists查询中。

Example:例子:

GET <your-index>/_search
{
  "query": {
    "bool": {
      "must": [
        {
          <put-your-query-here>
        },
        {
          "exists": {
            "field": "actual_start"
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果值不是elasticsearch中的null,如何计算字段 - How to count a field if value is not null in elasticsearch 如何从650 M数据中获取Elasticsearch中特定字段值的出现次数 - How to get occurrence count of specific field value in elasticsearch from 650 M data 基于字段值计数的ElasticSearch提升相关性 - ElasticSearch boosting relevance based on the count of the field value Elasticsearch:根据字段值和返回计数过滤掉特定文档的查询 - Elasticsearch: Query to filter out specific documents based on field value and return count 如何根据elasticsearch中存储的字段值获取前5个文档? - How to get top 5 documents based on a stored field value in elasticsearch? 如何从 Elasticsearch 获取字段的单个计数 - How to get the individual count of field from Elasticsearch ElasticSearch:查询以根据字段值查找对象的最大计数 - ElasticSearch: Query to find max of count of objects based on field value Elasticsearch。 获取特定索引字段中的值计数 - Elasticsearch. Get count of values in a field of specific index 根据特定的 uniqueid 字段在 elasticsearch 中获取聚合计数 - Get an aggregate count in elasticsearch based on particular uniqueid field 如何在弹性搜索查询中返回特定字段值 - How to return a specific field value in elasticsearch query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM