# Filtered not working with has\_parent in elasticsearch 1.3.0

**URL:** https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798
**Category:** Elasticsearch
**Created:** [September 15, 2014, 6:01pm UTC](https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798 "2014-09-15T18:01:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![roopednra](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@roopednra](https://discuss.elastic.co/u/roopednra)
#### Post date: [September 15, 2014, 6:01pm UTC](https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798/1 "2014-09-15T18:01:26Z")

</div>

In elasticsearch 1.3.0 _filtered_ not working with _has\_parent_. In _elasticsearch  
0.90.5_ its working fine.

I am using below query. In this query I need add filtered inside  
_has\_parent-\>query-\>filtered-\>bool-\>must_. But my basic query is not  
working.

```
{
   "query": {
      "has_parent": {
         "parent_type": "url",
         "query": {
           "match": {
              "affiliate_id": "1718489511"
           }
         }
      },
      "filtered": {
         "filter": {
            "bool": {
               "must": {
                  "terms": {
                     "country": [
                        "india"
                     ]
                  }
               }
            }
         }
      }
   }
}

```

Getting error message\* ElasticsearchParseException[Expected field name but  
got START\_OBJECT "filtered"\*

_Complete Error Message:-_

error: SearchPhaseExecutionException[Failed to execute phase [query], all  
shards failed;  
shardFailures {[hZgYLUmsQL2T8z1MY2eyNA][esindex][5]:  
SearchParseException[[esindex][5]:  
query[parent\_filter[url](filtered(affiliate\_id:1718489511)-\>cache(\_type  
:url))],from[-1],size[-1]:  
Parse Failure [Failed to parse source [{"query":{"has\_parent":{  
"parent\_type":"url","query":{"match":{"affiliate\_id":"1718489511"}}},  
"filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
]}}}}}}}]]];  
nested: ElasticsearchParseException[Expected field name but got  
START\_OBJECT "filtered"]; }  
{[OPG4zuQlQr2dFxUvRe2GWg][esindex][4]: RemoteTransportException[[  
server1][inet[/127.0.0.1:9300]]  
[search/phase/query]]; nested: SearchParseException[[esindex][4]: query  
[parent\_filter[url]  
(filtered(affiliate\_id:1718489511)-\>cache(\_type:url))],from[-1],size[-1  
]: Parse Failure  
[Failed to parse source [{"query":{"has\_parent":{"parent\_type":"url",  
"query":{"match":{"affiliate\_id":"1718489511"}}},  
"filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
]}}}}}}}]]];  
nested: ElasticsearchParseException[Expected field name but got  
START\_OBJECT "filtered"]; }

Any suggestion?

--  
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/683129a1-c757-4250-a97e-a15a4efbbaa5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/683129a1-c757-4250-a97e-a15a4efbbaa5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![roopednra](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@roopednra](https://discuss.elastic.co/u/roopednra)
#### Post date: [September 16, 2014, 11:27am UTC](https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798/2 "2014-09-16T11:27:15Z")

</div>

Any Suggestion??

On Monday, 15 September 2014 23:31:26 UTC+5:30, Roopendra Vishwakarma wrote:

> In elasticsearch 1.3.0 _filtered_ not working with _has\_parent_. In _elasticsearch  
> 0.90.5_ its working fine.
> 
> I am using below query. In this query I need add filtered inside  
> _has\_parent-\>query-\>filtered-\>bool-\>must_. But my basic query is not  
> working.
> 
> ```
> {
> "query": {
> "has_parent": {
> "parent_type": "url",
> "query": {
> "match": {
> "affiliate_id": "1718489511"
> }
> }
> },
> "filtered": {
> "filter": {
> "bool": {
> "must": {
> "terms": {
> "country": [
> "india"
> ]
> }
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> Getting error message\* ElasticsearchParseException[Expected field name  
> but got START\_OBJECT "filtered"\*
> 
> _Complete Error Message:-_
> 
> error: SearchPhaseExecutionException[Failed to execute phase [query], all  
> shards failed;  
> shardFailures {[hZgYLUmsQL2T8z1MY2eyNA][esindex][5]:  
> SearchParseException[[esindex][5]:  
> query[parent\_filter[url](filtered(affiliate\_id:1718489511)-\>cache(  
> \_type:url))],from[-1],size[-1]:  
> Parse Failure [Failed to parse source [{"query":{"has\_parent":{  
> "parent\_type":"url","query":{"match":{"affiliate\_id":"1718489511"}}},  
> "filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
> ]}}}}}}}]]];  
> nested: ElasticsearchParseException[Expected field name but got  
> START\_OBJECT "filtered"]; }  
> {[OPG4zuQlQr2dFxUvRe2GWg][esindex][4]: RemoteTransportException[[  
> server1][inet[/127.0.0.1:9300]]  
> [search/phase/query]]; nested: SearchParseException[[esindex][4]:  
> query[parent\_filter[url]  
> (filtered(affiliate\_id:1718489511)-\>cache(\_type:url))],from[-1],size  
> [-1]: Parse Failure  
> [Failed to parse source [{"query":{"has\_parent":{"parent\_type":"url",  
> "query":{"match":{"affiliate\_id":"1718489511"}}},  
> "filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
> ]}}}}}}}]]];  
> nested: ElasticsearchParseException[Expected field name but got  
> START\_OBJECT "filtered"]; }
> 
> Any suggestion?

--  
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/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [September 16, 2014, 11:47am UTC](https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798/3 "2014-09-16T11:47:57Z")

</div>

You need to wrap the has\_parent query in the query part of the filtered  
query:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

I don't see how this query could have worked in 0.90.5, since the format is  
incorrect, but if you wrap your has\_parent query inside the filtered  
query's query attribute then the format is correct and the query should  
work.

On 16 September 2014 13:27, Roopendra Vishwakarma [roopendramca@gmail.com](mailto:roopendramca@gmail.com)  
wrote:

> Any Suggestion??
> 
> On Monday, 15 September 2014 23:31:26 UTC+5:30, Roopendra Vishwakarma  
> wrote:
> 
> > In elasticsearch 1.3.0 _filtered_ not working with _has\_parent_. In _elasticsearch  
> > 0.90.5_ its working fine.
> > 
> > I am using below query. In this query I need add filtered inside  
> > _has\_parent-\>query-\>filtered-\>bool-\>must_. But my basic query is not  
> > working.
> > 
> > ```
> > {
> > "query": {
> > "has_parent": {
> > "parent_type": "url",
> > "query": {
> > "match": {
> > "affiliate_id": "1718489511"
> > }
> > }
> > },
> > "filtered": {
> > "filter": {
> > "bool": {
> > "must": {
> > "terms": {
> > "country": [
> > "india"
> > ]
> > }
> > }
> > }
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > Getting error message\* ElasticsearchParseException[Expected field name  
> > but got START\_OBJECT "filtered"\*
> > 
> > _Complete Error Message:-_
> > 
> > error: SearchPhaseExecutionException[Failed to execute phase [query],  
> > all shards failed;  
> > shardFailures {[hZgYLUmsQL2T8z1MY2eyNA][esindex][5]:  
> > SearchParseException[[esindex][5]:  
> > query[parent\_filter[url](filtered(affiliate\_id:1718489511)-\>cache(  
> > \_type:url))],from[-1],size[-1]:  
> > Parse Failure [Failed to parse source [{"query":{"has\_parent":{"  
> > parent\_type":"url","query":{"match":{"affiliate\_id":"1718489511"}}},  
> > "filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
> > ]}}}}}}}]]];  
> > nested: ElasticsearchParseException[Expected field name but got  
> > START\_OBJECT "filtered"]; }  
> > {[OPG4zuQlQr2dFxUvRe2GWg][esindex][4]: RemoteTransportException[[  
> > server1][inet[/127.0.0.1:9300]]  
> > [search/phase/query]]; nested: SearchParseException[[esindex][4]:  
> > query[parent\_filter[url]  
> > (filtered(affiliate\_id:1718489511)-\>cache(\_type:url))],from[-1],size  
> > [-1]: Parse Failure  
> > [Failed to parse source [{"query":{"has\_parent":{"parent\_type":"url"  
> > ,"query":{"match":{"affiliate\_id":"1718489511"}}},  
> > "filtered":{"filter":{"bool":{"must":{"terms":{"country":["india"  
> > ]}}}}}}}]]];  
> > nested: ElasticsearchParseException[Expected field name but got  
> > START\_OBJECT "filtered"]; }
> > 
> > Any suggestion?
> 
> --  
> 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/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0fb732f3-cc39-4de8-8ee4-52949ee8ca98%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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/CA%2BA76Tysp1bFs5A6Ec9rFGUjpQM8%2BTEUMJ5AGjf3cdUKWamw2g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BA76Tysp1bFs5A6Ec9rFGUjpQM8%2BTEUMJ5AGjf3cdUKWamw2g%40mail.gmail.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, 1:02am UTC](https://discuss.elastic.co/t/filtered-not-working-with-has-parent-in-elasticsearch-1-3-0/19798/4 "2017-07-06T01:02:02Z")

</div>


