hello, I have this sample search where the result I want to use in a highchart chart.
`GET _search
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{"terms": {"sexo": ["M","F"]}},
{"terms": {"doenca":
["Dengue","Intox Alcoolica","DST","Intox Alimentar","Animal Peconhento"
]}}]
}
}
}
},
"size": 0,
"aggs" : {
"municipios" : {
"terms" : {
"field" : "bairro",
"size":15
},
"aggs": {
"doencas": {
"terms": {
"field": "doenca", "size" : 5,"order" : { "_term" : "asc" }
}
}}
}
}
}`
As you can see, before the aggregations, it goes through some queries and terms.
The problem is that when it does not find the result to the Aggregation, he's not returning any data, and I need it to return 0 in the case.
a return Example:
{
"took": 69,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 5260,
"max_score": 0,
"hits": []
},
"aggregations": {
"municipios": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2234,
"buckets": [
{ {
"key": "Ouro Verde",
"doc_count": 248,
"doencas": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Animal Peconhento",
"doc_count": 38
},
{
"key": "DST",
"doc_count": 68
},
{
"key": "Dengue",
"doc_count": 1
},
{
"key": "Intox Alcoolica",
"doc_count": 101
},
{
"key": "Intox Alimentar",
"doc_count": 40
}
]
}
},
{
"key": "Municipal",
"doc_count": 244,
"doencas": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Animal Peconhento",
"doc_count": 34
},
{
"key": "DST",
"doc_count": 40
},
{
"key": "Intox Alcoolica",
"doc_count": 145
},
{
"key": "Intox Alimentar",
"doc_count": 25
}
]
}
},
The second bucket, did not return the key "Dengue", because in this case there was no record in the database, but I need to return the result, even if it is 0. For example:
{
"Key": "Dengue"
"Doc_count": 0
},
How can I make it returns 0 when there are no cases?
Note: I tried using min_doc_count, like this:
"aggs": {
"doencas": {
"terms": {
"field": "doenca","min_doc_count": 0, "size" : 5,"order" : { "_term" : "asc" }
}
}}
but using this way, it violates the terms of the query, and brings totally erroneous results.
thank you for attention