Using the Elasticsearch Aggregation Result as a Filter

I have an index of events that are grouped by the individual who attended the event, and each event is an attached document with a timestamp when they were present along with other information, such as the name of the event.

The source of the document is essentially as follows:

{
    "_id" : 1,
    "events" : [
        {
            "name" : "example event", // keyword type
            "eventDatetime" : "2018-02-26 04:02:57" // date type
        },
        {
            "name" : "other example event",
            "eventDatetime" : "2017-01-01 12:00:01"
        },
        {
            "name" : "final example event",
            "eventDatetime" : "2016-06-12 12:00:00"
        }
    ]
}

API , , " , 3- 2016 ". , SQL having count(*) > 3. , . . , .

, , , , , , , .

Elasticsearch ?

+4
1

(, ), -

GET /_search
{
    "_source": false,
    "query": {
        "nested" : {
            "path" : "events",
            "query" : {
                "range" : {
                    "events.eventDatetime" :{
                        "gte": "01/01/2016",
                        "lte": "12/31/2016",
                        "format": "MM/dd/yyyy"
                    }
                }
            }
        }
    },
    "aggs":{
        "user_event_count":{
            "terms":{
                "field": "id",
                "min_doc_count":4
            }
        }
    }
}

, . ,

0
source

Source: https://habr.com/ru/post/1694691/


All Articles