# Invalid Filters executing

**URL:** <https://discuss.elastic.co/t/invalid-filters-executing/7607>\
**Category:** Elasticsearch\
**Created:** [May 8, 2012, 11:49pm UTC](https://discuss.elastic.co/t/invalid-filters-executing/7607 "2012-05-08T23:49:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_2](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jeremy\_2](https://discuss.elastic.co/u/Jeremy_2)\
**Post date:** [May 8, 2012, 11:49pm UTC](https://discuss.elastic.co/t/invalid-filters-executing/7607/1 "2012-05-08T23:49:32Z")

</div>

Hello ES'ers.

I am using the ES Java API. Some of our developers that are less  
familiar with ES are creating filters that execute properly, but  
they're not correct.

The following filters both run, but the 2nd one is actually incorrect:

////////// CORRECT

{  
"from": 0,  
"size": 10,  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"id": "derp"  
}  
},  
{  
"term": {  
"name": "index.html"  
}  
}  
]  
}  
}  
}

////////// INCORRECT

{  
"from" : 0,  
"size" : 10,  
"filter" : {  
"bool" : {  
"must" : {  
"term" : {  
"id" : "derp"  
}  
},  
"must" : {  
"term" : {  
"name" : "index.html"  
}  
}  
}  
}  
}

The second filter simply matches any document with the name of  
index.html, completely ignoring the id term that has been added. I  
understand that this syntax is incorrect, but unfortunately it's quite  
easy to create these filters using the Java API.

Is there any way to either validate a query/filter for 'correctness',  
or a setting in ES that will cause these filters/queries to just fail?

What should I do to prevent developers that I am working with from  
doing this?

Thanks!  
Jeremy (jereanon)

---

<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:** [May 9, 2012, 9:56am UTC](https://discuss.elastic.co/t/invalid-filters-executing/7607/2 "2012-05-09T09:56:54Z")

</div>

Both are valid formats and works: [gist:2643463 · GitHub](https://gist.github.com/2643463). The Java  
API has statically typed builders for queries and filters, and there is  
validity checks on queries and filters.

On Wed, May 9, 2012 at 2:49 AM, Jeremy [jeremy@possiblyfaulty.com](mailto:jeremy@possiblyfaulty.com) wrote:

> Hello ES'ers.
> 
> I am using the ES Java API. Some of our developers that are less  
> familiar with ES are creating filters that execute properly, but  
> they're not correct.
> 
> The following filters both run, but the 2nd one is actually incorrect:
> 
> ////////// CORRECT
> 
> {  
> "from": 0,  
> "size": 10,  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "id": "derp"  
> }  
> },  
> {  
> "term": {  
> "name": "index.html"  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> ////////// INCORRECT
> 
> {  
> "from" : 0,  
> "size" : 10,  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "term" : {  
> "id" : "derp"  
> }  
> },  
> "must" : {  
> "term" : {  
> "name" : "index.html"  
> }  
> }  
> }  
> }  
> }
> 
> The second filter simply matches any document with the name of  
> index.html, completely ignoring the id term that has been added. I  
> understand that this syntax is incorrect, but unfortunately it's quite  
> easy to create these filters using the Java API.
> 
> Is there any way to either validate a query/filter for 'correctness',  
> or a setting in ES that will cause these filters/queries to just fail?
> 
> What should I do to prevent developers that I am working with from  
> doing this?
> 
> Thanks!  
> Jeremy (jereanon)

---

<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, 3:29am UTC](https://discuss.elastic.co/t/invalid-filters-executing/7607/3 "2017-07-06T03:29:38Z")

</div>

Closed on July 6, 2017, 3:29am UTC


