# Es JOIN DATA TYPE AGGRETION

**URL:** <https://discuss.elastic.co/t/es-join-data-type-aggretion/139108>\
**Category:** Elasticsearch\
**Created:** [July 9, 2018, 8:27am UTC](https://discuss.elastic.co/t/es-join-data-type-aggretion/139108 "2018-07-09T08:27:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![firattaskin93](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@firattaskin93](https://discuss.elastic.co/u/firattaskin93)\
**Post date:** [July 9, 2018, 8:27am UTC](https://discuss.elastic.co/t/es-join-data-type-aggretion/139108/1 "2018-07-09T08:27:09Z")

</div>

Hi heros,  
I used join data type and its my query.

```
{
  "size": 0, 
  "query": {
    "has_child": {
      "type": "variation",
      "query": {
        "bool": {
          "must_not": [
            {
            "match": {
              "stock": 0
            }
          }
        ]
      }
    }
  }
  },
  "aggs": {
    "sizes": {
      "terms": {
        "field": "size.keyword",
        "size": 10
      },
      "aggs": {
        "to-product": {
          "children": {
            "type" : "product" 
          },
          "aggs": {
            "top-names": {
              "terms": {
                "field": "name.keyword",
                "size": 10
              }
            }
          }
        }
      }
   
    }
  }
}

```

My problem is aggretion give me all sizes but i need only in stock sizes from query response.  
(query working true.)

Example Product

```
PUT products/prod/2?refresh
{
  "name": "Koton Kazak",
  "my_join_field": "product" 
}

PUT products/prod/10?routing=2&refresh 
{
  "size": "xxl",
  "color": "blau",
  "stock":7,
  "my_join_field": {
    "name": "variation", 
    "parent": "2" 
  }
}
```

---

<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:** [August 6, 2018, 8:27am UTC](https://discuss.elastic.co/t/es-join-data-type-aggretion/139108/2 "2018-08-06T08:27:10Z")

</div>

Closed on August 6, 2018, 8:27am UTC

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