# Search w/Filter Error Message Confusing

**URL:** https://discuss.elastic.co/t/search-w-filter-error-message-confusing/3257
**Category:** Elasticsearch
**Created:** [August 25, 2010, 2:47pm UTC](https://discuss.elastic.co/t/search-w-filter-error-message-confusing/3257 "2010-08-25T14:47:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kenneth\_Loafman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kenneth_loafman/32/2224_2.png) [@Kenneth\_Loafman](https://discuss.elastic.co/u/Kenneth_Loafman)
#### Post date: [August 25, 2010, 2:47pm UTC](https://discuss.elastic.co/t/search-w-filter-error-message-confusing/3257/1 "2010-08-25T14:47:19Z")

</div>

Hi,

The following query gets the error:  
"[filtered] requires a 'query' element"  
yet its clear from the json dump of the query that 'query' is in the  
'filtered' dictionary, so what's the real problem?

{  
"query": {  
"filtered": {  
"filter": {  
"or": [  
{  
"term": {  
"lang": "en"  
}  
},  
{  
"term": {  
"lang": "es"  
}  
}  
]  
},  
"query": {  
"query\_string": {  
"use\_dis\_max": true,  
"fields": [  
"content",  
"title",  
"author\_name"  
],  
"query": "xxxxxxx"  
},  
"from": 50,  
"size": 3  
}  
}  
}  
}

...Thanks,  
...Ken

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 25, 2010, 3:09pm UTC](https://discuss.elastic.co/t/search-w-filter-error-message-confusing/3257/2 "2010-08-25T15:09:00Z")

</div>

The query is malformed. The or/and filters need an inner `filters` element  
in them. What happens is that it screws up the pull parsing. I just pushed  
some things to improve on that. The first is to throw an exception if no  
filters are identified for or/and parsing. The second is nicer format for  
it: [Query DSL: Improve `or` and `and` filters to accept just array of filters · Issue #336 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/336).

One more thing, the size and from should be "top level" fields.

-shay.banon

On Wed, Aug 25, 2010 at 5:47 PM, Kenneth Loafman  
[kenneth.loafman@gmail.com](mailto:kenneth.loafman@gmail.com)wrote:

> Hi,
> 
> The following query gets the error:  
> "[filtered] requires a 'query' element"  
> yet its clear from the json dump of the query that 'query' is in the  
> 'filtered' dictionary, so what's the real problem?
> 
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "or": [  
> {  
> "term": {  
> "lang": "en"  
> }  
> },  
> {  
> "term": {  
> "lang": "es"  
> }  
> }  
> ]  
> },  
> "query": {  
> "query\_string": {  
> "use\_dis\_max": true,  
> "fields": [  
> "content",  
> "title",  
> "author\_name"  
> ],  
> "query": "xxxxxxx"  
> },  
> "from": 50,  
> "size": 3  
> }  
> }  
> }  
> }
> 
> ...Thanks,  
> ...Ken

---

<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, 4:20am UTC](https://discuss.elastic.co/t/search-w-filter-error-message-confusing/3257/3 "2017-07-06T04:20:22Z")

</div>


