# Aggregate between 2 Index and vice versa

**URL:** <https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409>\
**Category:** Kibana\
**Created:** [April 11, 2019, 1:19pm UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409 "2019-04-11T13:19:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [April 11, 2019, 1:19pm UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409/1 "2019-04-11T13:19:58Z")

</div>

> ELK Stack Version 6.6.0

Hi all,

I'm struggle with following case and hope you can help me to understand how it is working technically.

I have 2 Index in one Node  
1 named NaO  
1 named BaO

NaO held ProductGroups, ProductTypes and their TotalTurnovers  
BaO held the same ProductTypes but additional information like: parParameters and parValues

What I try in Kibana:

Build 2 Visuals and add them into a Dashboard:

Pie with BaO:  
Inner Circlce: ProductTypes (text)  
Middle: parParameters (text)  
Out: parValues (text)

Horizontal Bars with NaO:  
Y Axis = TotalTurnover (float)  
X Axis = ProductTypes (text)  
Split Series: ProductGroups (text)

Now:  
If I select the ProductTypes (Inner) in Pie / BaO  
Turnover in NaO now aggregated and show me the the right value = works fine

If I select the NaO ProductTypes the Pie / BaO is also filtering the right values = works fine

Bu if I select in Pie / BaO the parParameters (middle) or parValues (out)  
no TotalTurnover in NaO is showing / noresults.

Why?  
And what do I have to do to get the Turnovers when "not" select over ProductTypes if that is technically possible.

Data BaO Pie Request:

```
{
  "aggs": {
    "4": {
      "terms": {
        "field": "ProductTypes.keyword",
        "size": 10,
        "order": {
          "_count": "desc"
        }
      },
      "aggs": {
        "1": {
          "cardinality": {
            "field": "ProductGroups.keyword"
          }
        },
        "3": {
          "terms": {
            "field": "parParameters.keyword",
            "size": 10,
            "order": {
              "_count": "desc"
            }
          },
          "aggs": {
            "1": {
              "cardinality": {
                "field": "ProductGroups.keyword"
              }
            },
            "2": {
              "terms": {
                "field": "parValues.keyword",
                "size": 10,
                "order": {
                  "_count": "desc"
                }
              },
              "aggs": {
                "1": {
                  "cardinality": {
                    "field": "ProductGroups.keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0,
  "_source": {
    "excludes": []
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "gte": 1549807055871,
              "lte": 1554987455871,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "filter": [
        {
          "match_all": {}
        },
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": [
        {
          "match_phrase": {
            "parParameters.keyword": {
              "query": "testset"
            }
          }
        }
      ]
    }
  }
}

```

Data NaO Bar Request:

```
{
  "aggs": {
    "4": {
      "terms": {
        "field": "ProductTypes.keyword",
        "size": 5,
        "order": {
          "1": "desc"
        }
      },
      "aggs": {
        "1": {
          "sum": {
            "field": "TotalTurnover"
          }
        },
        "3": {
          "terms": {
            "field": "ProductGroups.keyword",
            "size": 5,
            "order": {
              "1": "desc"
            }
          },
          "aggs": {
            "1": {
              "sum": {
                "field": "TotalTurnover"
              }
            }
          }
        }
      }
    }
  },
  "size": 0,
  "_source": {
    "excludes": []
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "range": {
            "@timestamp": {
              "gte": 1549807055871,
              "lte": 1554987455871,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "filter": [
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

```

Thanks and Brdgs  
Thorben

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [April 19, 2019, 11:14am UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409/2 "2019-04-19T11:14:22Z")

</div>

With the way you have your data set up this is how it works for now. Filtering on a piece of the pie chart in a dashboard will add a global filter for all the visualizations in that dashboard.  
What i would do is add the data from the NaO index to the BaO index, to each corresponding document. This way you will have all the fields from those 2 visualizations available in one index, so the filter will not show no results now.

---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [April 19, 2019, 1:22pm UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409/3 "2019-04-19T13:22:20Z")

</div>

You might also want to try turning this setting on in Management \> Advanced Settings;

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/d/adf40b43556319b7862daa28bbc06a579baab8f8.png)

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [April 24, 2019, 12:43pm UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409/4 "2019-04-24T12:43:08Z")

</div>

Hi Marius,  
thanks for your reply.  
I tried this way but looks like I must flattened the datasource a bit more to achive this result.

Thanks and Brgds

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 22, 2019, 12:43pm UTC](https://discuss.elastic.co/t/aggregate-between-2-index-and-vice-versa/176409/5 "2019-05-22T12:43:12Z")

</div>

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