[英]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
替换为_search
, hits
下的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.