If else script filter does not work


(Shalini) #1

Hi All,

I am using elastic search version 1.4.2.
I am creating a scripted term as below.

"aggregations" : {
    "aggr~~derived_i~g" : {
      "terms" : {
        "script" : "if(doc['g'].value > 50) {'big sal'} else {'small sal'}",
        "size" : 0,
        "order" : {
          "_term" : "asc"
        }
      }

This works fine and I am able to fetch both the bucket values.
Now I am trying to filter the terms, which doesn't work!

"query" : {
    "filtered" : {
      "query" : {
        "match_all" : { }
      },
      "filter" : {
        "and" : {
          "filters" : [ {
            "and" : {
              "filters" : [ {
                "not" : {
                  "filter" : {
                    "or" : {
                      "filters" : [ {
                        "script" : {
                          "script" : "doc['g'].value > 50 == param0 ",
                          "params" : {
                            "param0" : false
                          }
                        }
                      } ]
                    }
                  }
                }
              } ]
            }
          } ]
        }
      }
    }

while I change the param0 to true, it does not return the values as expected. It returns values with doc['g'].value > 50 in both the cases.
Script filter like
"script" : " !( doc['g'].value > 50 ) "
Will it work?

Thanks
Shalini


(Shalini) #2

Did someone face this issue, any help would be greatly appreciated.

Thanks
Shalini


(Shalini) #3

Any help would be greatly appreciated, As I am still to resolve this issue.

Thanks
Shalini


(system) #4