Mamen
Mamen

Reputation: 1436

Group by date and object elasticsearch

Hi i'm new in elasticsearch, i have schema like this:

"_source": {
            "user_email": "[email protected]",
            "eventtime": "2019-11-07T15:07:35.439043",
            "shipping_address": {
                "zipcode": "28234"
          }
 },

and i want to perform a grouping by date and also group zipcode each date, i can group it by date but after add aggs for zipcode, the error appears:

[16:20] unable to parse BaseAggregationBuilder with name [group_shipzip]: parser not found

this is my query looks like:

{
    "_source": ["user_email","shipping_address.zipcode","eventtime"],
     "query" : {
        "match_phrase_prefix" : {
            "user_email": "[email protected]"
        }
    },
    "aggs": {
        "group_by_date":{
            "date_histogram":{
                "field" : "eventtime",
                "interval" : "1d"
            }
        },
        "aggs":{
            "group_shipzip":{
                "terms":{
                    "field": "shipping_address.zipcode.keyword"
                }
            }
        }

    }
}

Upvotes: 0

Views: 87

Answers (1)

Assael Azran
Assael Azran

Reputation: 2993

Try this:

   {
    "_source": ["user_email", "shipping_address.zipcode", "eventtime"],
    "query": {
        "match_phrase_prefix": {
            "user_email": "[email protected]"
        }
    },
    "aggs": {
        "group_by_date": {
            "date_histogram": {
                "field": "eventtime",
                "interval": "1d"
            },

            "aggs": {
                "group_shipzip": {
                    "terms": {
                        "field": "shipping_address.zipcode.keyword"
                    }
                }
            }
        }

    }
}

Upvotes: 1

Related Questions