# Has\_child filter and min\_children

**URL:** <https://discuss.elastic.co/t/has-child-filter-and-min-children/20221>\
**Category:** Elasticsearch\
**Created:** [October 13, 2014, 5:19pm UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221 "2014-10-13T17:19:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [October 13, 2014, 5:19pm UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221/1 "2014-10-13T17:19:30Z")

</div>

I have ES 1.3.4 installed and i am trying to use a filter on has child, but  
I keep getting the error "[has\_child] filter does not support  
[min\_children]"

Even though the documents  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html) specifically  
show it...

The has\_child filter allows you to specify that a minimum and/or maximum  
number of children are required to match for the parent doc to be  
considered a match:

{  
"has\_child" : {  
"type" : "comment",  
"min\_children": 2, [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html#CO49-2](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html#CO49-2)  
"max\_children": 10, [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html#CO49-3](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html#CO49-3)  
"filter" : {  
"term" : {  
"user" : "john"  
}  
}  
}  
}

Any help I can get on this would be greatly appreciated!

{  
"query": {

```
  "filtered": {
     "query": {
        "match_all": {}
     },
     "filter": {
        "and": [
            {
            "has_child":{
                "type":"service",
                "min_children":2,
                "filter":{"match_all": {}}
            }
            },
           {
              "term": {
                 "ismd": true
              }
           },
           {
              "terms": {
                 "owk": [
                    23621
                 ]
              }
           },
           {
              "terms": {
                 "oowk": [
                    23621
                 ]
              }
           },
           {
              "term": {
                 "ipl": false
              }
           },
           {
              "terms": {
                 "pwk": [
                    21754
                 ]
              }
           },
           {
              "term": {
                 "isb": false
              }
           }
        ]
     }
  }

```

},  
"from": 0,  
"size": 0,  
"aggs": {

```
  "unique": {
     
     "cardinality": {
        "field": "hhk",
        "precision_threshold": 40000
     }
  }

```

}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fa54ac23-cb19-4a58-9192-d50cc5476d05%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa54ac23-cb19-4a58-9192-d50cc5476d05%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [October 14, 2014, 4:09pm UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221/2 "2014-10-14T16:09:28Z")

</div>

ANy thoughts anyone?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6c97ec75-8c4e-44a3-92e2-1a54c8317e86%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6c97ec75-8c4e-44a3-92e2-1a54c8317e86%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [October 15, 2014, 12:50pm UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221/3 "2014-10-15T12:50:24Z")

</div>

I've come up with something that will allow me to get the minimun level...  
Now, do I need to do this at the client level to get the 'max' number...  
say I want a range between 5 and 10... how do I limit the results to n  
number of children?

{  
"min\_score": 5,  
"query": {  
"filtered": {  
"query": {  
"has\_child": {  
"type": "service",  
"score\_type": "total",  
"query": {  
"match\_all": {}  
}  
}  
},  
"filter": {  
"and": [  
{  
"terms": {  
"owk": [  
23621  
]  
}  
},  
{  
"terms": {  
"oowk": [  
23621  
]  
}  
},  
{  
"term": {  
"ismd": true  
}  
},  
{  
"and": [  
{  
"terms": {  
"owk": [  
23621  
]  
}  
},  
{  
"terms": {  
"oowk": [  
23621  
]  
}  
},  
{  
"term": {  
"ipl": false  
}  
},  
{  
"terms": {  
"pwk": [  
21754  
]  
}  
},  
{  
"range": {  
"my": {  
"gte": 1980,  
"lte": 2015  
}  
}  
},  
{  
"term": {  
"isb": false  
}  
}  
]  
}  
]  
}  
}  
},  
"from": 0,  
"size": 0,  
"aggs": {  
"unique": {  
"cardinality": {  
"field": "hhk",  
"precision\_threshold": 40000  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5539c864-c50c-4ded-8077-bcef3d87deeb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5539c864-c50c-4ded-8077-bcef3d87deeb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Darren\_McDaniel](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@Darren\_McDaniel](https://discuss.elastic.co/u/Darren_McDaniel)\
**Post date:** [October 15, 2014, 1:13pm UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221/4 "2014-10-15T13:13:42Z")

</div>

I guess if I bang at it hard enough.. I'll find a solution... this  
'Appears' to work... 🙂

{

"min\_score": 0,

"query": {

```
  "function_score": {

     "boost_mode": "multiply",

     "functions": [

        {

           "script_score": {

              "params": {

                 "min_value":0,

                 "max_value": 5

              },

              "script": "_score <= max_value && _score >= 

```

min\_value?1:-1"

```
           }

        }

     ],

     "query": {

        "filtered": {

           "query": {

              "has_child": {

                 "type": "service",

                 "score_type": "total",

                 "query": {

                    "match_all": {}

                 }

              }

           },

           "filter": {

              "and": [

                 {

                    "terms": {

                       "owk": [

                          23621

                       ]

                    }

                 },

                 {

                    "terms": {

                       "oowk": [

                          23621

                       ]

                    }

                 },

                 {

                    "term": {

                       "ismd": true

                    }

                 },

                 {

                    "and": [

                       {

                          "terms": {

                             "owk": [

                                23621

                             ]

                          }

                       },

                       {

                          "terms": {

                             "oowk": [

                                23621

                             ]

                          }

                       },

                       {

                          "term": {

                             "ipl": false

                          }

                       },

                       {

                          "terms": {

                             "pwk": [

                                21754

                             ]

                          }

                       },

                       {

                          "range": {

                             "my": {

                                "gte": 1980,

                                "lte": 2015

                             }

                          }

                       },

                       {

                          "term": {

                             "isb": false

                          }

                       }

                    ]

                 }

              ]

           }

        }

     }

  }

```

},

"from": 0,

"size": 0,

"aggs": {

```
  "unique": {

     "cardinality": {

        "field": "hhk",

        "precision_threshold": 40000

     }

  }

```

}

}

On Wednesday, October 15, 2014 8:50:24 AM UTC-4, Darren McDaniel wrote:

> I've come up with something that will allow me to get the minimun level...  
> Now, do I need to do this at the client level to get the 'max' number...  
> say I want a range between 5 and 10... how do I limit the results to n  
> number of children?
> 
> {  
> "min\_score": 5,  
> "query": {  
> "filtered": {  
> "query": {  
> "has\_child": {  
> "type": "service",  
> "score\_type": "total",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> },  
> "filter": {  
> "and": [  
> {  
> "terms": {  
> "owk": [  
> 23621  
> ]  
> }  
> },  
> {  
> "terms": {  
> "oowk": [  
> 23621  
> ]  
> }  
> },  
> {  
> "term": {  
> "ismd": true  
> }  
> },  
> {  
> "and": [  
> {  
> "terms": {  
> "owk": [  
> 23621  
> ]  
> }  
> },  
> {  
> "terms": {  
> "oowk": [  
> 23621  
> ]  
> }  
> },  
> {  
> "term": {  
> "ipl": false  
> }  
> },  
> {  
> "terms": {  
> "pwk": [  
> 21754  
> ]  
> }  
> },  
> {  
> "range": {  
> "my": {  
> "gte": 1980,  
> "lte": 2015  
> }  
> }  
> },  
> {  
> "term": {  
> "isb": false  
> }  
> }  
> ]  
> }  
> ]  
> }  
> }  
> },  
> "from": 0,  
> "size": 0,  
> "aggs": {  
> "unique": {  
> "cardinality": {  
> "field": "hhk",  
> "precision\_threshold": 40000  
> }  
> }  
> }  
> }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5a4c4564-a582-424b-aa8f-d59e9e1474ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5a4c4564-a582-424b-aa8f-d59e9e1474ff%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:56am UTC](https://discuss.elastic.co/t/has-child-filter-and-min-children/20221/5 "2017-07-06T00:56:04Z")

</div>


