Get the number of people who have bought twice

Hello friends

I have an index of orders as follows

{
        "offer" : {
          "type" : "unsigned_long"
        },
        "order_number" : {
          "type" : "keyword"
        },
        "payable" : {
          "type" : "unsigned_long"
        },    
        "status" : {
          "type" : "byte"
        },
        "total" : {
          "type" : "unsigned_long"
        },
        "user_id" : {
          "type" : "keyword"
        }
}

How can I get the number of people who have bought twice ??

Relevant field user_id

Hi.

Maybe this:

{
  "size": 0,
  "aggs": {
    "purchases-twice": {
      "terms": {
        "field": "user_id",
        "size": 10
      },
      "aggs": {
        "count_purchases": {
          "value_count": {
            "field": "total"
          }
        },
        "sales_bucket_filter": {
          "bucket_selector": {
            "buckets_path": {
              "countPurchases": "count_purchases"
            },
            "script": "params.countPurchases == 2"
          }
        }
      }
    }
  }
}

hi

not working!

Empty result? I used the same mapping you reported.

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