Invalid Filters executing


(Jeremy-2) #1

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)


(Shay Banon) #2

Both are valid formats and works: 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 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)


(system) #3