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
Throw parsing exception if terms filter or query has more than one field #5137
Conversation
The TermsFilter constructor that we use indeed only supports filtering on a single field but there is another constructor that takes a list of terms (instead of a list of BytesRefs) and supports filtering based on terms that come from different fields. Maybe we could use it? |
+1 to fixing the terms filter parser to allow different fields! |
Is it really a common use case, that justifies complicating the terms filter? compared to having a terms filter that is then OR'ed using the regular query DSL? |
I don't think it complicates it at all. to me it just does what you would expect. |
maybe we can see an example of how this would look DSL wise, and decide based on that. No problem with adding it if it makes sense. |
to me it woudl just look like this: {
"constant_score" : {
"filter" : {
"terms" : {
"user" : ["kimchy", "elasticsearch"],
"company" : ["elasticsearch"]
}
}
}
} |
That can work, though it will be the first filter that works across fields in ES, and I personally find the lack of boolean logic between fields strange (not very evident if its AND or OR). Would love to hear other people thoughts. |
Naive answer: writing filter like this makes me think that we want that both Terms filters to match. |
We are handling boolean logic to some degree through execution mode. So, perhaps, we can extend it to the case of multiple fields. It might become messy though. |
so to me the confusion is in the name. It's called |
@s1monw it becomes more complicated because before it was one dimensional (multiple values). Now it's two dimensional: (multiple fields and multiple values). Your simplification (which is natural for you since it follows Lucene design) is only one possible way to interpret the query. It also doesn't fit the current query syntax nicely since you don't specify this query as:
|
fair enough - I thought my example was simple and consistent: {
"constant_score" : {
"filter" : {
"terms" : {
"user" : ["kimchy", "elasticsearch"],
"company" : ["elasticsearch"]
}
}
}
} but apparently it isn't... I don't have strong feelings but it feels to me it's the wrong thing todo to throw an exception.... |
A wildcard form like this |
I'm torn on this. This is a frequent mistake that users make; they clearly expect something like this to work. I agree completely with @kimchy that it is not obvious whether the logic is AND or OR. And I agree with @dadoonet that the most likely interpretation is as an AND, so:
... would be interpreted as:
But then there is no easy way to specify that the AND should be an OR. In the example of wildcarded field names, the user would expect an OR:
In fact, looking at the current
So you can't have a field called
We could do:
But that still doesn't give us place to include the overall AND/OR logic for multiple fields, unless we add a top-level One way to do it would be to have different filter names, eg
(We're missing And really, that's not very far from:
...but it doesn't handle wildcards in the field name. So, lots of rumination without any solutions. What I dislike about all of these suggestions is that they complicate the My inclination would be to leave things as they are, except that we throw an exception if more than one field name is specified. |
Revisiting this PR: changing the behaviour of the |
LGTM but also looks like this is the current behavior. Did this PR already get merged ? If so can it be closed ? |
11ec18d
to
28a7d63
Compare
Closes #5014