# Multiple search filters in has\_child query

**URL:** <https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634>\
**Category:** Elasticsearch\
**Created:** [January 27, 2020, 10:40am UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634 "2020-01-27T10:40:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnkary](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@johnkary](https://discuss.elastic.co/u/johnkary)\
**Post date:** [January 27, 2020, 10:40am UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634/1 "2020-01-27T10:40:49Z")

</div>

Hi all!  
I have an index with parent-child capability and the has\_child query below with a filter-range applied on children (child\_field\_1). My issues here are 2.

1. I cannot put multiple filters to children (only one),

My query:

```
GET npk/_search
    {
      "query": {
        "has_child": {
          "type": "body",
          "min_children": 1,
         "query": {
              "range": {
                 "child_field_1": {
                    "gte": 5,
                    "lte": 10
        },
                 "child_field_2": {
                    "gte": 8,
                    "lte": 12
        }  
} },
       "inner_hits": {}
        } } }

```

Response:

```
"type": "parsing_exception",
        "reason": "[range] query doesn't support multiple fields, found [child_field_1] and [child_field_2]",

```

1. I cannot put a filter for parent.

My query:

```
GET npk/_search
    {
      "query": {
        "range": {
                 "parent_field_1": {
                    "gte": 1,
                    "lte": 10
        }},
        "has_child": {
          "type": "body",
          "min_children": 1,
         "query": {
              "range": {
                 "child_field_1": {
                    "gte": 5,
                    "lte": 10
        }
} },
       "inner_hits": {}
        } } }

```

Response:

```
"type": "parsing_exception",
        "reason": "[range] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
```

---

<div class="post-metadata">

**Author:** ![johnkary](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@johnkary](https://discuss.elastic.co/u/johnkary)\
**Post date:** [January 29, 2020, 1:06pm UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634/2 "2020-01-29T13:06:21Z")

</div>

Here again with an ansewer to my question.  
I managed to insert multiple filters with multiple has\_child buckets, but it doesn't work 100%. I mean, it gives me results but not in the right range for field: `"gpsSats": {"gte": 17,"lte": 17}` . It brings me results also out of this range despite i have included in my query the " **must**" clause which stands for **AND**. What is wrong here? Any help please?

My query:

```auto
GET npk/_search
{ "_source": ["CameraNo"],
  "query": {
      "bool": {  
        "must": [
          {
            "range": {
                "CameraNo": {
                  "gte": 1,
                  "lte": 4
                  }
                } 
              },
          {
            "has_child": {
               "type": "body",
                 "query": { 
                   "range": {
                     "gpsSats": {
                       "gte": 17,
                       "lte": 17
                 }
               }
             }
           }
          },
          {
            "has_child": {
               "type": "body",
                 "query": {
                   "range": {
                     "ndvi_1": {
                       "gte": 0.4,
                       "lte": 0.5
                  }
                }
              }
            }
          },
          { 
             "has_child": {
               "type": "body",
                 "query": {
                   "range": {
                     "ndvi_0": {
                       "gte": 0.494,
                       "lte": 0.495
                }
              }
            },
              "inner_hits": {"_source": ["ndvi_0","ndvi_1","gpsSats"]}
          }
        } 
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 29, 2020, 3:04pm UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634/3 "2020-01-29T15:04:48Z")

</div>

can you provide a **full, but minimal reproduction** including index creation & mapping, document indexing, the query you are executing, plus documents that get returned compared to what you expect?

You can use the `inner_hits` query to check which children have matched, in case that helps debugging.

Thank you!

---

<div class="post-metadata">

**Author:** ![johnkary](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@johnkary](https://discuss.elastic.co/u/johnkary)\
**Post date:** [January 29, 2020, 3:40pm UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634/4 "2020-01-29T15:40:06Z")

</div>

index creation:

```
PUT /npk
{ 
    "settings" : {
        "index" : {
            "number_of_shards" : 3, 
            "number_of_replicas" : 2 
        }
    },
  "dynamic": true,
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field" : {
                "type" : "join",
                "relations": {
                    "header": "body"
                }}
      }}}

```

A sample of documents indexed. Practically, it's a log file in which as 'parent' i used the header of this file (the vertical list with the fields with '#' in front of). And below this, it's the body of the file, which acts as 'children'.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/b/fb7f2dcaaab3c8d42d2454b35dbb15f73075060f.png)

Below, is a part of an answer i get and as you see, the field "gpsSats" has brought to me values  
'17' which are correct, but also values '20' which are out of range i specified.

```
{
  "took": 35,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 6,
    "max_score": 4,
    "hits": [
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "1",
        "_score": 4,
        "_source": {
          "CameraNo": 3
        },
        "inner_hits": {
          "body": {
            "hits": {
              "total": 53,
              "max_score": 1,
              "hits": [
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "12013",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.563597,
                    "ndvi_0": 0.494044,
                    "gpsSats": 17
                  }
                },
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "12065",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.555584,
                    "ndvi_0": 0.494376,
                    "gpsSats": 17
                  }
                },
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "12074",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.562169,
                    "ndvi_0": 0.494615,
                    "gpsSats": 17
                  }
                }
              ]
            }
          }
        }
      },
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "51798",
        "_score": 4,
        "_source": {
          "CameraNo": 3
        },
        "inner_hits": {
          "body": {
            "hits": {
              "total": 53,
              "max_score": 1,
              "hits": [
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "52858",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.511705,
                    "ndvi_0": 0.494054,
                    "gpsSats": 20
                  }
                },
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "52895",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.522266,
                    "ndvi_0": 0.494395,
                    "gpsSats": 20
                  }
                },
                {
                  "_index": "npk",
                  "_type": "doc",
                  "_id": "52917",
                  "_score": 1,
                  "_routing": "1",
                  "_source": {
                    "ndvi_1": 0.523934,
                    "ndvi_0": 0.494879,
                    "gpsSats": 20
                  }
                }
              ]
            }
          }
        }
      }
}

```

**Notes** : '_CameraNo_' is a parent field and '_ndvi\_0_', '_ndvi\_1_', '_gpsSats_' are children fields.

---

<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:** [February 26, 2020, 3:40pm UTC](https://discuss.elastic.co/t/multiple-search-filters-in-has-child-query/216634/5 "2020-02-26T15:40:14Z")

</div>

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