[英]how to get count of not-null value based on specific field in Elasticsearch
我有彈性搜索索引,我需要字段之一(“actual_start”)不為空的記錄總數,我該怎么做?
我已經寫了這個查詢,我想將非空實際起始值的計數附加到我的查詢結果中:
$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']
]
],
]
],
]
]
];
嘗試這個:
GET <your-index>/_count
{
"query": {
"exists": {
"field": "actual_start"
}
}
}
然后您可以讀取count
數值,該值將為您提供actual_start
不為空的記錄總數。
您還可以將_count
替換為_search
, hits
下的total
價值將為您提供總計數(如果您還需要hits
)。
如果你想做相反的事情(所有actual_start
為空的記錄):
GET <your-index>/_count
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "actual_start"
}
}
]
}
}
}
更新
如果我理解正確,您希望將當前查詢附加到exists
查詢中。
例子:
GET <your-index>/_search
{
"query": {
"bool": {
"must": [
{
<put-your-query-here>
},
{
"exists": {
"field": "actual_start"
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.