Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Make ParseContext's IndexQueryParserService accessible #8248
I have the following problem writing an own query parser from my own package:
My query parser has to internally create another Elasticsaearch query and parse it (which is actually a workaround: I need to create a MoreLikeThis query, but I dont want to replicate all code to generate the native Lucene Query). So I use MoreLikeThisQueryBuilder to create a BytesReference of the newly constructed query, so I can parse it to a Lucene Query.
Of course I cannot do the parseContext.parseInnerQuery, because the newly constructed query is in a separate BytesReference. Instead I do the same trick like WrappedQuery:
The problem is now: I need to clone the QueryParseContext. WrappedQueryParser just creates a new instance, but it needs the index name (easy to get) and IndexQueryParserService. Unfortunately, the latter is package private.
I would be happy if this could be solved. As this above stuff is used quite often, I think the best solution would be to allow to clone ParseContext or add a method to create a new one from an existion one (copy constructor). The other way would be to make the field accessible.
The current workaround is to use reflection to get the field...
@kimchy thats of course the easy thing, as I said :-)
My idea here was to make the common case "parse some other query in context of current ParseContext" easier: The same code is duplicated over and over. Maybe add something like ParseContext#parseQueryInCurrentContext(BytesReference), a setup like parseInnerQuery() - just cloning itsself. By that it could reused in WrapperQueryParser, WrapperFilterParser, and TemplateQueryParser - and for my case.
The repetition is not terrible if you create a new instance of the
Regardless, I don't see a reason why we can't expose the