Skip to content

Conversation

javanna
Copy link
Member

@javanna javanna commented Apr 2, 2025

FieldCapabilitiesFetcher acquires a searcher to perform basic checks that don't actually require a searcher to be performed, as they are purely mappings driven. Instead, we can reuse the existing QueryRewriteContext to perform such checks and entirely avoid acquiring a searcher.

FieldCapabilitiesFetcher acquires a searcher to perform basic checks that don't
actually require a searcher to be performed, as they are purely mappings driven.
Instead, we can reuse the existing QueryRewriteContext to perform such checks
and entirely avoid acquiring a searcher.
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Apr 2, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

final Engine.Searcher searcher;
if (alwaysMatches(indexFilter)) {
// no need to open a searcher if we aren't filtering, but make sure we are reading from an up-to-dated shard
indexShard.readAllowed();
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure what the purpose of this is, I think we can drop it as well, can't we?


public boolean hasMappings() {
return mappingLookup.hasMappings();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

these methods rely on state that's already available in query rewrite context, there's no good reason to expose them only in SearchExecutionContext, that's more of a leftover from before we were able to rewrite based on mappings only.

@javanna javanna changed the title Acquire search in field caps only when needed Acquire searcher in field caps only when needed Apr 2, 2025
@javanna javanna changed the title Acquire searcher in field caps only when needed Acquire searcher in can match only when needed Apr 2, 2025
@javanna javanna changed the title Acquire searcher in can match only when needed Acquire searcher in field caps only when needed Apr 2, 2025
@javanna javanna added the >bug label Apr 2, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @javanna, I've created a changelog YAML for you.

if (searcher != null && canMatchShard(shardId, indexFilter, nowInMillis, searchExecutionContext) == false) {
QueryRewriteContext queryRewriteContext = indexService.newQueryRewriteContext(() -> nowInMillis, runtimeFields, null);
var indexMode = indexService.getIndexSettings().getMode();
if (canMatchShard(shardId, indexFilter, nowInMillis, queryRewriteContext) == false) {
Copy link
Member Author

Choose a reason for hiding this comment

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

here is what I missed: while this method takes a query rewrite context, it can indirectly call convertToSearchExecutionContext which performs additional actions, and only does something when the original argument was a SearchExecutionContext. That means a searcher may be needed, but not necessarily.

@javanna javanna closed this Apr 2, 2025
@javanna javanna deleted the fix/can_match_less_searcher branch April 2, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants