Query to display terms associated to a filter aggregation on particular event


(Nikhil Nambiar) #1

Hi,

I need a help for an elastic search query,

My query below is as follows

    {

  "size":0,

"aggs":{

      "group-by-customerid":{

        "terms":{

          "field":"customer_id.keyword"

        },

        "aggs":{

          "card-load":{

            "filter":{

              "term":{

                "Event":2003

              }

            },

            "aggs":{

              "load-balance":{

                "terms":{

                  "field":"balance"

                }

              }

            }

          },

          "reset-cycle":{

            "filter":{

              "term":{

                "Event":4012

              }

            },

            "aggs":{

              "reset-balance":{

                "terms":{

                  "field":"balance"

                }

              }

            }

          }

        }

      }

    }

}

This is a working query this query help me to get every customer_id in my doc who has event 2003 and 4012 with its respective balance associate to the customer_id.

Now I want to get only those customer_id's whose balance of card-load event(Event:2003) + balance of reset-cycle event(Event:4012) to be equal to 0.

I used bucket_selector as below

{

  "size":0,

"aggs":{

      "group-by-customerid":{

        "terms":{

          "field":"customer_id.keyword"

        },

        "aggs":{

          "card-load":{

            "filter":{

              "term":{

                "Event":2003

              }

            },

            "aggs":{

              "load-balance":{

                "terms":{

                  "field":"balance"

                }

              },

              "loadBalance1":{

                "bucket_selector":{

                  "buckets_path":{

                    "load-Balance":"load-balance"

                  }

                }

              }

            },

            "loadBalance2":{

              "bucket_selector":{

                "buckets_path":{

                  "load-Balance2":"loadBalance1"

                }

              }

            }

          },

          "reset-cycle":{

            "filter":{

              "term":{

                "Event":4012

              }

            },

            "aggs":{

              "reset-balance":{

                "terms":{

                  "field":"balance"

                }

              },

              "resetBalance1":{

                "bucket_selector":{

                  "buckets_path":{

                    "reset-Balance":"reset-balance"

                  }

                }

              }

            },

            "resetBalance2":{

              "bucket_selector":{

                "buckets_path":{

                  "reset-Balance2":"resetBalance1"

                }

              }

            }

          },

          "ResultBucket":{

            "bucket_selector":{

              "buckets_path":{

                "loadBucket":"loadBalance2",

                "resetBucket":"resetBalance2"

              },

              "script":"params.loadBucket+params.resetBucket==0"

            }

          }

        }

      }

    }

} 

And query fails.

I am not getting where I am going wrong

Thank you


Query that sum balance of different event
(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.