Aggregation Script with ID and use it in condition

Hi All,

I am using script in aggregation and need two things

  1. min_doc_count
  2. Use aggerartion in condition

All I am trying is to group by outlet and statationno and if count > 3 send alert.

Below is my script:

 "aggs": {
            "scripted": {
              "terms": {
                "script": {
                  "source": "doc['OutletId'].value + ' ' + doc['StationNo'].value"
                },
                "size": 3
              }
            }
          }

I fixed the aggregation condition. Still looking for min_doc_count

"aggs": {
            "group_by_outlet": {
              "terms": {
                "script": {
                  "source": "doc['OutletId'].value + ' ' + doc['StationNo'].value"
                }
              }
            }
          }

All sorted.

  "aggs": {
    "group_by_outlet": {
      "terms": {
        "script": {
          "source": "doc['OutletId'].value + ' ' + doc['StationNo'].value"
        }
      },
      "aggs": {
        "criticals": {
          "bucket_selector": {
            "buckets_path": {
              "doc_count": "_count"
            },
            "script": "params.doc_count > 2"
          }
        }
      }
    }
  }

  "condition": {
	"script": {
	  "source": "return (ctx.payload.aggregations.group_by_outlet.buckets.size() > 0 && ctx.payload.aggregations.group_by_outlet.buckets.0.doc_count >= params.threshold)",
	  "lang": "painless",
	  "params": {
		"threshold": 3
	  }
	}
  }
1 Like

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