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

Percolator to support parsing script score query with params #101051

Merged
merged 10 commits into from
Oct 24, 2023

Conversation

javanna
Copy link
Member

@javanna javanna commented Oct 18, 2023

While dot expansion is disabled when parsing percolator queries at index time, as that would interfere with query parsing, we still use a wrapper parser that is conservative about what methods it supports, assuming that document parsing needs nextToken and not much more. Turns out that when parsing queries instead, we need to support all the XContentParser methods including map, list etc.

This commit adds a test for script score query parsing through document parsing via percolator field mapper, and removes the limitations in the wrapper parser.

Closes #97377

While dot expansion is disabled when parsing percolator queries at index
time, as that would interfere with query parsing,  we still use a wrapper parser
that is conservative about what methods it supports, assuming that
document parsing needs nextToken and not much more. Turns out that when
parsing queries instead, we need to support all the XContentParser
methods including map, list etc.

This commit adds a test for script score query parsing through document
parsing via percolator field mapper, and removes the limitations in the
wrapper parser.
@javanna javanna added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.11.1 v8.12.0 labels Oct 18, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Oct 18, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @javanna, I've updated the changelog YAML for you.

@Override
public List<Object> listOrderedMap() throws IOException {
throw new UnsupportedOperationException();
}
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 wonder if this is safe. The intention where I added these was to make sure that we support the bare minimum we need, as I was not sure if these methods could be safely supported when expanding dots. Maybe we could throw uoe only if we are actually expanding dots, or not at all like I do here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The actual implementations here will be those in AbstractXContentParser which just delegates things to nextToken(), currentToken(), and the various value methods. So I think it should be safe. It would be good to add some tests that check it does actually do what we expect though?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be good to add some tests that check it does actually do what we expect though?

Right, that's a good idea. I tried through the percolator tests but it became difficult, yet we can just expand the unit test for the parser itself. Will do that.

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 added tests, and figured that when expanding dots is enabled, the behaviour is unexpected in that we don't expand dots at all (we'd need to override an additional nextFieldName method). Given that we don't need the functionality when expanding dots, as we can safely assume that when parsing ordinary documents we never call map or list, I made all methods conditional of whether dots expansion is enabled or not.

Copy link
Member

@piergm piergm left a comment

Choose a reason for hiding this comment

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

LGTM

@javanna javanna added the auto-backport Automatically create backport pull requests when merged label Oct 18, 2023
@javanna
Copy link
Member Author

javanna commented Oct 23, 2023

I took a bit more time to add extensive test coverage. I realized I could register a custom query plugin in PercolatorFieldMapperTests and register a custom query that used all those exotic parser methods that we initially thought are never called.

@javanna javanna merged commit b07feb5 into elastic:main Oct 24, 2023
13 checks passed
@javanna javanna deleted the fix/percolator_script_score_query branch October 24, 2023 09:03
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.11

javanna added a commit to javanna/elasticsearch that referenced this pull request Oct 24, 2023
…#101051)

While dot expansion is disabled when parsing percolator queries at index
time, as that would interfere with query parsing,  we still use a wrapper parser
that is conservative about what methods it supports, assuming that
document parsing needs nextToken and not much more. Turns out that when
parsing queries instead, we need to support all the XContentParser
methods including map, list etc.

This commit adds a test for script score query parsing through document
parsing via percolator field mapper, and removes the limitations in the
wrapper parser when dots expansion is disabled.
javanna added a commit that referenced this pull request Oct 24, 2023
While dot expansion is disabled when parsing percolator queries at index
time, as that would interfere with query parsing,  we still use a wrapper parser
that is conservative about what methods it supports, assuming that
document parsing needs nextToken and not much more. Turns out that when
parsing queries instead, we need to support all the XContentParser
methods including map, list etc.

This commit adds a test for script score query parsing through document
parsing via percolator field mapper, and removes the limitations in the
wrapper parser when dots expansion is disabled.

Closes #97377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.11.1 v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using script query on percolator fails to parse after upgrade to 8.6 because of subobjects parsing
4 participants