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

Type filters should not have a performance impact when there is a single type. #17350

Merged
merged 1 commit into from Mar 29, 2016

Conversation

Projects
None yet
2 participants
@jpountz
Copy link
Contributor

jpountz commented Mar 25, 2016

Today, if you call /index/type/_search instead of /index/_search, elasticsearch
will automatically insert a type filter to only match documents of the given
type. This commit uses a new TypeQuery instead of a TermQuery for this filter,
which rewrites to a MatchAllDocsQuery when all documents of a shard match the
filtered type. This is helpful because BooleanQuery has a special rewrite rule
to remove MatchAllDocsQuery as FILTER clauses. So for instance if your query is
+body:"quick fox" #_type:my_type, it will be rewritten to
+body:"quick fox" #*:* which is then rewritten to body:"quick fox".

}
}

public static class TypeQuery extends Query {

This comment has been minimized.

Copy link
@rjernst

rjernst Mar 25, 2016

Member

Does this need to be public or could it be private or pkg private?

This comment has been minimized.

Copy link
@rjernst

rjernst Mar 25, 2016

Member

I see because it is used in tests it has to be public for now...we really need to fix this isolation of classes from there tests, which require so much to be public. But that's unrelated to this change. :)

This comment has been minimized.

Copy link
@jpountz

jpountz Mar 29, 2016

Author Contributor

Agreed.

@rjernst

This comment has been minimized.

Copy link
Member

rjernst commented Mar 25, 2016

LGTM

Type filters should not have a performance impact when there is a sin…
…gle type. #17350

Today, if you call /index/type/_search instead of /index/_search, elasticsearch
will automatically insert a type filter to only match documents of the given
type. This commit uses a new TypeQuery instead of a TermQuery for this filter,
which rewrites to a MatchAllDocsQuery when all documents of a shard match the
filtered type. This is helpful because BooleanQuery has a special rewrite rule
to remove MatchAllDocsQuery as FILTER clauses. So for instance if your query is
`+body:"quick fox" #_type:my_type`, it will be rewritten to
`+body:"quick fox" #*:*` which is then rewritten to `body:"quick fox"`.

@jpountz jpountz force-pushed the jpountz:enhancement/single_type_filter branch to 4bd27bc Mar 29, 2016

@jpountz jpountz merged commit 4bd27bc into elastic:master Mar 29, 2016

1 check passed

CLA Commit author is a member of Elasticsearch
Details

@jpountz jpountz deleted the jpountz:enhancement/single_type_filter branch Mar 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.