At most filter in Elastic search

21 Views Asked by At

I am pretty new to elastic search and trying to create query for the below scenario.

"Filter records that have type "Purchase" added atleast 2 times in last 6days which have value greater than 2000"

"Filter records that have type "Purchase" added exactly 2 times in last 6days which have value greater than 2000"

"Filter records that have type "Purchase" added atmost 2 times in last 6days which have value greater than 2000"

I have used below mentioned query for first and second scenarios. But for atmost what filter should be used, because for 'atleast' it's min_doc_size, for 'exactly' it's size.

Is there anyother workaround to achieve the atmost filter?

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "Purchase"
          }
        },
        {
          "range": {
            "metadata.time.insert": {
              "gte": "now-6d/d",
              "lte": "now"
            }
          }
        },
        {
          "range": {
            "metadata.time.insert": {
              "gte": "now-2M/M",
              "lte": "now"
            }
          }
        },
        {
          "range": {
            "properties.value":{"gte": "2000"}
          }
        }
      ]
    }
  },
  "aggs": {
    "users": {
      "terms": {
        "field": "profile.id",
        "min_doc_size": 2
      }
    }
  },
  "size": 0
}
0

There are 0 best solutions below