Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On query DSL errors display the expected type for nested objects. #2805

Closed
gibrown opened this issue Mar 20, 2013 · 3 comments
Closed

On query DSL errors display the expected type for nested objects. #2805

gibrown opened this issue Mar 20, 2013 · 3 comments

Comments

@gibrown
Copy link
Contributor

gibrown commented Mar 20, 2013

It seems like a common problem I am seeing developers new to ES struggling with is how to fit the pieces of the query DSL together. Returning more structured feedback about what the query DSL is expecting feels like it would help.

Some examples from helping someone recently:

'filter' : {
  'not' : {
    'post_id' : [ 1, 2 ]
  }
},

Problem here is the NOT filter should have a filter inside of it rather than a field name

If the error response could return the type of expected data at each level that would aid debugging. For example this could return:
"filter": { "not" : "error: expects a filter" } }

Another case:

'filter' : {
  'and' : {
    'terms' : {
      'post_type' : ['post']
    },
    'not' : {
      'terms' : {
        'post_id' : [1, 2]
      }
    }
  }
},

Error:
"filter": { "and": "error: expects an array of filter objects" } }

With more complex nesting:

'filter' : {
  'and' : [
    {
      'terms' : {
       'post_type' : ['post']
      }
    },
    {
      'not' : {
        'post_id' : [1,2]
      }
    }
  ]
}

Error:
"filter": { "and": [{"terms" : "ok"}, {"not" : "error: expects a filter"} } }

Not entirely sure how feasible this is, or if there is better syntax or a more standard method for reporting such structured errors.

@clintongormley
Copy link

I don't think this is really feasible. Some queries accept a large number of options (eg query_string). These days we don't just accept bad query syntax like we did before, so at least the user gets an error about which part of the query is bad.

That said I think it could still be improved, eg in a deeply nested query, it may not be obvious which clause is being referred to. Perhaps we could have the equivalent of a query "stack trace" here.

@gibrown
Copy link
Contributor Author

gibrown commented Jul 23, 2014

Thanks for taking a look at this.

A query stack trace would help a lot I think.

There are a few other things that make the output very tough to grok.

For instance, here is a bad query I just ran across our 8 indices:

{
   "query": {
      "filtered": {
            "match_all": {}
      }
   }
}

Even for this simple mistake, the error output is a bad user experience: https://cloudup.com/cuHH-WJ9Uaf

This output:

  • Repeats the same error multiple times which means that the user doesn't read any of it.
  • The query is not pretty printed so it is hard to parse.
  • Just tells the user what is illegal rather than saying what was expected. (Not clear to me if the expected output was the part of my original suggestion that was not feasible vs the suggestion of returning a JSON structure).

If the fix is to reformat the output, then it would be nice to address these points as well.

@clintongormley
Copy link

Closing as duplicate of #3303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants