I am trying to filter based on the cluster field and whether the podName field has a value. Then I want to filter out some fields with specific values but I get the values for other cluster fields than the one specified.
So the following query will also return values for cluster2 and cluster3.
I can't figure out what the correct syntax is.
{
"size":50,
"query":{
"bool":{
"must":[
{
"range":{
"timestamp":{
"gte":"now-1h"
}
}
},
{
"query_string":{
"query":"(podstatus.podName:* AND cluster:cluster1) AND NOT podstatus.containerStatus:true AND NOT podstatus.phase:Running AND NOT podstatus.phase:Succeeded AND NOT podstatus.started: true"
}
}
]
}
}
}
Sample document
{
"timestamp": "2020-07-09T17:30:04",
"cluster": "cluster1",
"namespace": "kube-system",
"podstatus.podName": "cronjob-kubernetes-resource-monitor-1594233600-4frbc",
"podstatus.containerStatus": "false",
"podstatus.restartCount": 0,
"podstatus.started": "false",
"podstatus.phase": "Succeeded"
}
Mapping
{
"cluster-resources-cluster1-2020.07.08-000001" : {
"mappings" : {
"properties" : {
"allocated" : {
"properties" : {
"pods-percent" : {
"type" : "float"
}
}
},
"capacity" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"mem" : {
"type" : "long"
},
"pods" : {
"type" : "long"
}
}
},
"cluster" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"depstatus" : {
"properties" : {
"availableReplicas" : {
"type" : "long"
},
"deploymentName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"readyReplicas" : {
"type" : "long"
},
"replicas" : {
"type" : "long"
},
"unavailableReplicas" : {
"type" : "long"
},
"updatedReplicas" : {
"type" : "long"
}
}
},
"namespace" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podstatus" : {
"properties" : {
"containerStatus" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"phase" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"podName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"restartCount" : {
"type" : "long"
},
"started" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"requests" : {
"properties" : {
"cpu" : {
"type" : "long"
},
"cpu-percent" : {
"type" : "float"
},
"mem" : {
"type" : "long"
},
"mem-percent" : {
"type" : "float"
},
"pods" : {
"type" : "long"
}
}
},
"timestamp" : {
"type" : "date"
}
}
}
}
}
)at the very end. Could you remove that and give it a try.podstatusis anestedtype or justobjecttype. Would help if you can also share the mapping.