Skip to content

RangeQuery on date field cannot be nested inside SpanMultiTermQuery#12123

Closed
cbuescher wants to merge 2 commits intoelastic:masterfrom
cbuescher:spanmultiterm+range
Closed

RangeQuery on date field cannot be nested inside SpanMultiTermQuery#12123
cbuescher wants to merge 2 commits intoelastic:masterfrom
cbuescher:spanmultiterm+range

Conversation

@cbuescher
Copy link
Copy Markdown
Member

This PR explains the issue in #12122 by adding an integration test to SearchQueryTests. The additional query setup triggers the following internal parsing exception.

nested: SearchParseException[failed to parse search source [{"query":{"span_or":{"clauses":[{"span_multi":{"match":{"range":{"date":{"from":"2010-01-01","to":"2011-01-01","include_lower":true,"include_upper":true}}}}}]}}}]]; nested: QueryParsingException[spanMultiTerm [match] must be of type multi term query]; 

This PR only adds the test code for #12122 since I have no idea for a fix yet. Mainly to illustrate the problem and discuss solutions.

@cbuescher cbuescher added >bug >test Issues or PRs that are addressing/adding tests :Query DSL labels Jul 8, 2015
@martijnvg
Copy link
Copy Markdown
Member

The only reason LateParsingQuery exists is for the percolator... Because queries are parsed at index time and we want to resolve now at percolate time. We could hack to make it work here (just invoking rewrite in query is instance of LateParsingQuery in SpanMultiTermQueryParser#parse) but that doesn't feel right to me.

Rather what I'm leaning towards to, is to just forbid the usage of now in the percolator. This way we don't need to LateParsingQuery work around any more. (unless there is a better solution here)

@cbuescher
Copy link
Copy Markdown
Member Author

Thanks, I have the feeling that the now option in percolator is quiet useful and people wouldn't like removing it. What are the other downsides of catching this special case in the parsing step and then rewriting it?

@martijnvg
Copy link
Copy Markdown
Member

Thanks, I have the feeling that the now option in percolator is quiet useful and people wouldn't like removing it.

I have the same feeling :(

What are the other downsides of catching this special case in the parsing step and then rewriting it?

It adds complexity and the LateQueryParsing workaround is leaking to other places in the code base, but if we 're okay with catching this special case, then I think we can go for it. We should just put a big comment on top of that if statement.

This if statement should make the test pass:

if (subQuery instanceof DateFieldMapper.DateFieldType.LateParsingQuery) {
   subQuery = ((DateFieldMapper.DateFieldType.LateParsingQuery) subQuery).rewrite(null);
}

(Also LateParsingQuery needs to be made public)

@cbuescher
Copy link
Copy Markdown
Member Author

Okay, such SpanMultiTermQuery (with nestes date RangeQuery) would not work with now in percolator then, or rather have now fixed at the moment of rewrite?

@cbuescher
Copy link
Copy Markdown
Member Author

Tried to make test pass with the suggested workaround, but now test complains with java.lang.IllegalStateException: field "date" was indexed without position data; cannot run SpanQuery [...] at org.apache.lucene.search.spans.SpanWeight.scorer(SpanWeight.java:98) which makes perfect sense because I cannot see why a date field would have positions. Maybe it makes sense to not allow this kind of range query inside a Span Query and we should reject it? One would have to look at the mapping of the field though. I guess Range queries on numeric fields in this context also don't make much sense?

@javanna
Copy link
Copy Markdown
Contributor

javanna commented Jul 10, 2015

I agree @cbuescher probably disallowing it is the best way forward at least for now

@cbuescher
Copy link
Copy Markdown
Member Author

On the query refactoring branch we now decided to reject SpanMultiTermQueries that wrap inner queries that don't produce MultiTerm lucene queries like the date field RangeQuery, so I'm closing this PR.

@cbuescher cbuescher closed this Aug 11, 2015
@cbuescher cbuescher added won't fix and removed >test Issues or PRs that are addressing/adding tests labels Aug 11, 2015
@cbuescher cbuescher deleted the spanmultiterm+range branch March 11, 2016 11:51
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search/Search Search-related issues that do not fall into other categories won't fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants