@@ -107,6 +107,9 @@ func (e ESExpr) binaryNodeToEsQuery(n *ast.BinaryNode) (interface{}, error) { //
107
107
108
108
case "==" :
109
109
if leftStr , ok := left .(string ); ok {
110
+ if right == nil {
111
+ return e .mustNotExistQuery (leftStr ), nil
112
+ }
110
113
return e .termQuery (leftStr , right ), nil
111
114
}
112
115
result , err := getQueryExprResult (n .String ())
@@ -117,6 +120,9 @@ func (e ESExpr) binaryNodeToEsQuery(n *ast.BinaryNode) (interface{}, error) { //
117
120
118
121
case "!=" :
119
122
if leftStr , ok := left .(string ); ok {
123
+ if right == nil {
124
+ return e .mustExistQuery (leftStr ), nil
125
+ }
120
126
return e .mustNotQuery (leftStr , right ), nil
121
127
}
122
128
result , err := getQueryExprResult (n .String ())
@@ -257,6 +263,30 @@ func (ESExpr) mustNotQuery(field string, value interface{}) map[string]interface
257
263
}
258
264
}
259
265
266
+ func (ESExpr ) mustExistQuery (field string ) map [string ]interface {} {
267
+ return map [string ]interface {}{
268
+ "bool" : map [string ]interface {}{
269
+ "must" : map [string ]interface {}{
270
+ "exists" : map [string ]interface {}{
271
+ "field" : field ,
272
+ },
273
+ },
274
+ },
275
+ }
276
+ }
277
+
278
+ func (ESExpr ) mustNotExistQuery (field string ) map [string ]interface {} {
279
+ return map [string ]interface {}{
280
+ "bool" : map [string ]interface {}{
281
+ "must_not" : map [string ]interface {}{
282
+ "exists" : map [string ]interface {}{
283
+ "field" : field ,
284
+ },
285
+ },
286
+ },
287
+ }
288
+ }
289
+
260
290
func (ESExpr ) rangeQuery (field , operator string , value interface {}) map [string ]interface {} {
261
291
return map [string ]interface {}{
262
292
"range" : map [string ]interface {}{
0 commit comments