NonReserved can only contain tokens Found nested rule – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-8.9

Briefly, this error occurs when Elasticsearch encounters a nested rule in a place where it expects only tokens. This is typically due to a misconfiguration in the Elasticsearch query or mapping. To resolve this issue, you should review your Elasticsearch query or mapping to ensure that it is correctly formatted. Make sure that you are not using nested rules where only tokens are expected. If necessary, you may need to restructure your data or adjust your query to avoid using nested rules in this context.

This guide will help you check for common problems that cause the log ” nonReserved can only contain tokens. Found nested rule: ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: parser, plugin.

Log Context

Log “nonReserved can only contain tokens. Found nested rule:” class name is We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 public void exitNonReserved(SqlBaseParser.NonReservedContext context) {
 // tree cannot be modified during rule enter/exit _unless_ it's a terminal node
 if ((context.getChild(0) instanceof TerminalNode) == false) {
 int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex();
 throw new ParsingException("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule));
 }  // replace nonReserved words with IDENT tokens


How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?