Aggregations Flashcards

1
Q

How do you count unique values in elastic?

A
GET < index >/_search
{
   size: 0,
    aggs: {
        "< aggregation name >": {
            "cardinality": {
                field: "< field name >"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why should you use aggregations only on keyword fields?

A

Because analysed fields are broken down into tokens and it would be too expensive to aggregate them.
You get an error if you try saying the process would required uninverting the index which takes a lot of memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do remove the documents output in an aggregations query if you’re not interested in seeing the documents, just the counts?

A

Set “size: 0”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you do a sum aggregation?

A
GET < index >/_search
{
   size: 0,
    aggs: {
        "< aggregation name >": {
            "sum": {
                field: "< field name >"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you do an average aggregation?

A
GET < index >/_search
{
   size: 0,
    aggs: {
        "< aggregation name >": {
            "avg": {
                field: "< field name >"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you do a terms aggregation and what is it?

A

It aggregates and counts the values of a field into buckets.

GET < index >/_search
{
   size: 0,
    aggs: {
        "< aggregation name >": {
            "terms": {
                field: "< field name >"
                size: 10,
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a date histogram aggregation and how do you do it?

A

Gives you a count of events by day/month/etc

GET < index >/_search
{
   size: 0,
    aggs: {
        "< aggregation name >": {
            "date_histogram": {
                field: "< field name >" # date field
                calendar_interval: "day|month|etc"
}

TODO: Read more about other types of aggregations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you perform nested aggregations?

A
GET < index >/_search
{
   size: 0,
   aggs: {
     "< agg name >": {
          terms: {
            field: "< fild name >",
         }
         aggs: {
              ....
         }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you sort your nested aggregations?

A
agg: {
     "< name >: {
         terms: {
               ....
               order: {
                  "< other aggregation >": "desc|asc"
              }
         },
                "aggs": {
                      "< other aggregation >": ....
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 2 different types of pipeline aggregation?

A
  • Sibling aggregation

- Parent aggregation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you perform sibling aggregations?

A
{
   aggs: {
        < agg name >: { ... },
        < sibbling aggregation name >: {
            "sum_bucket": {
                 buckets_path: "path>to>aggregation>...."
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a sibling aggregation?

A

Allows you to aggregate the output of an other aggregation. For example, you can bucket the counts with one aggregation and calculate the total with a sibling aggregation by simply adding the result of the buckets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a pipeline aggregation?

A

An aggregation that takes the output of another aggregation as input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between sibling and parent aggregation pipeline?

A

TODO: Do some more research on this because it wasn’t super clear.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly