private String indexPrefix(String indexPath) {
        int position = tokens.getPosition();
        String index = null;

        try {
            List<Token> firstWord = new ArrayList<>();
            List<Token> secondWord = new ArrayList<>();

            tokens.skip(LSQUAREBRACKET);

            if ( ! tokens.currentIs(WORD) && ! tokens.currentIs(NUMBER) && ! tokens.currentIs(UNDERSCORE)) {
                return null;
            }

            firstWord.add(tokens.next());

            while (tokens.currentIsNoIgnore(UNDERSCORE)
                   || tokens.currentIsNoIgnore(WORD)
                   || tokens.currentIsNoIgnore(NUMBER)) {
                firstWord.add(tokens.next());
            }

            while (tokens.currentIsNoIgnore(DOT)) {
                secondWord.add(tokens.next());
                if (tokens.currentIsNoIgnore(WORD) || tokens.currentIsNoIgnore(NUMBER)) {
                    secondWord.add(tokens.next());
                } else {
                    return null;
                }
                while (tokens.currentIsNoIgnore(UNDERSCORE)
                       || tokens.currentIsNoIgnore(WORD)
                       || tokens.currentIsNoIgnore(NUMBER)) {
                    secondWord.add(tokens.next());
                }
            }

            if ( ! tokens.skipNoIgnore(COLON))
                return null;

            index = concatenate(firstWord) + concatenate(secondWord);

            String fullIndex = indexFacts.getCanonicName(indexPath + index);
            if (indexPath.isEmpty()) {
                index = fullIndex;
            }
            else { // replace index (the last path element) by the dealiased value
                int lastDot = fullIndex.lastIndexOf('.');
                if (lastDot > 0)
                    index = fullIndex.substring(lastDot + 1);
            }

            if ( ! indexFacts.isIndex(fullIndex)) { // Only if this really is an index
                // Marker for the "finally" block
                index = null;
                return null;
            } else {
                if (nothingAhead(false)) {
                    // correct index syntax, correct name, but followed by noise. Let's skip this.
                    nothingAhead(true);
                    position = tokens.getPosition();
                    index = indexPrefix(indexPath);
                }
            }
            return index;
        } finally {
            if (index == null) {
                tokens.setPosition(position);
            }
        }
    }
Returns an item and whether it had an explicit index ('indexname:' prefix).

@param indexPath the index name prefix this is in the context of, only non-empty if this is
                 inside a sameElement. The path includes the index name and the trailing dot.
@return an item and whether it has an explicit index, or a Pair with the first element null if none
container-search/src/main/java/com/yahoo/prelude/query/parser/StructuredParser.java