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

Rewrite range queries with open bounds to exists query #26160

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Aug 11, 2017

This change rewrites range query with open bounds to an exists query that should be faster to execute.

Fixes #22640

This change rewrites range query with open bounds to an exists query that should be faster to execute.

Fixes elastic#22640
@jimczi jimczi added :Search/Search Search-related issues that do not fall into other categories >enhancement v6.1.0 v7.0.0 labels Aug 11, 2017
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at this out of interest and it looks good to me. I might miss some subtleties though, so maybe a second opinion might be good.

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return new MatchNoDocsQuery("No mappings yet");
}
if (fieldNamesFieldType.isEnabled()) {
return ExistsQueryBuilder.newFilter(context, fieldName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe leave a comment that we need to check whether the fieldNames mapper is enabled because otherwise we fail exists queries

@jimczi jimczi merged commit d896e62 into elastic:master Aug 14, 2017
@jimczi jimczi deleted the range_query_open_bounds branch August 14, 2017 07:50
jimczi added a commit that referenced this pull request Aug 14, 2017
* Rewrite range queries with open bounds to exists query

This change rewrites range query with open bounds to an exists query that should be faster to execute.

Fixes #22640
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Aug 14, 2017
* master: (30 commits)
  Rewrite range queries with open bounds to exists query (elastic#26160)
  Fix eclipse compilation problem (elastic#26170)
  Epoch millis and second formats parse float implicitly (Closes elastic#14641) (elastic#26119)
  fix SplitProcessor targetField test (elastic#26178)
  Fixed typo in README.textile (elastic#26168)
  Fix incorrect class name in deleteByQuery docs (elastic#26151)
  Move more token filters to analysis-common module
  reindex: automatically choose the number of slices (elastic#26030)
  Fix serialization of the `_all` field. (elastic#26143)
  percolator: Hint what clauses are important in a conjunction query based on fields
  Remove unused Netty-related settings (elastic#26161)
  Remove SimpleQueryStringIT#testPhraseQueryOnFieldWithNoPositions.
  Tests: reenable ShardReduceIT#testIpRange.
  Allow `ClusterState.Custom` to be created on initial cluster states (elastic#26144)
  Teach the build about betas and rcs (elastic#26066)
  Fix wrong header level
  inner hits: Unfiltered nested source should keep its full path
  Document how to import Lucene Snapshot libs when elasticsearch clients (elastic#26113)
  Use `global_ordinals_hash` execution mode when sorting by sub aggregations. (elastic#26014)
  Make the README use a single type in examples. (elastic#26098)
  ...
@colings86
Copy link
Contributor

colings86 commented Aug 14, 2017

@jimczi when we first wrote the range query rewrite stuff I initially had this optimisation to rewrite to an exists query in the case where the query entirely overlaps the range of values on the shard, but when I did this I ran into issues with highlighting (tests failed). This was because an exists query will not highlight the value that matched the range. I assume all the tests passed this time but I am curious what has changed, will highlighting still work on these range queries?

I know there is a argument to say that doing highlighting on a numeric field should not be supported but I think it would be weird if highlighting on a numeric field sometimes worked (when not rewritten to exists) and sometimes didn't work (when rewritten to exists). If we don't want to support highlighting on numeric/date fields maybe we should explicitly forbid it?

@jimczi
Copy link
Contributor Author

jimczi commented Aug 14, 2017

I don't know when it was removed but we don't support range query in the highlighters. These queries are not extracted nor rewritten by the three remaining highlighters (plain, unified and fvh) . We don't support numeric queries as well which is why I merged this pr.
I couldn't find the pr that removed the tests for numeric queries though. Maybe it was on old numeric types because the new point queries are not compatible with highlighting.

@colings86
Copy link
Contributor

@jimczi ok, it could well have been on the old numeric types, but as we don't support numeric fields int eh remaining highlighters my fear has been resolved. Thanks for looking into it. ++ on this change.

@jimczi
Copy link
Contributor Author

jimczi commented Aug 14, 2017

It's not explicit though, we accept the query if it targets a numeric field but we ignore the numeric queries so nothing is highlighted. Maybe we should fail the query if the field is a numeric field and its using one of the es highlighters (but should work if you use a custom highlighter) ?

@jpountz
Copy link
Contributor

jpountz commented Aug 14, 2017

I like the idea but we might have to be careful with wildcards in case they match both string and numeric fields?

@colings86
Copy link
Contributor

We should definitely add something to the documentation to say what field types can be highlighted I don't see anything about it at the moment (although maybe I'm missing it): https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-request-highlighting.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories v6.1.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants