Far*_*aei 3 elasticsearch elasticsearch-aggregation
我有弹性搜索索引,并且需要其中一个字段(“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']
]
],
]
],
]
]
];
Run Code Online (Sandbox Code Playgroud)
看一眼存在查询
尝试这个:
GET <your-index>/_count
{
"query": {
"exists": {
"field": "actual_start"
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后您可以读取该count值,该值将为您提供记录的总数actual_start值,该值将为您提供非空
您还可以替换_count为_search,total下面的值hits将为您提供总计数(如果您还想要hits)。
如果您想做相反的事情(所有记录均为actual_start空):
GET <your-index>/_count
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "actual_start"
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新
如果我理解正确的话,您想将当前查询附加到exists。
例子:
GET <your-index>/_search
{
"query": {
"bool": {
"must": [
{
<put-your-query-here>
},
{
"exists": {
"field": "actual_start"
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3850 次 |
| 最近记录: |