Span first match must be of type span query – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-8.9

Briefly, this error occurs when the “span_first” query in Elasticsearch is not correctly formatted. The “match” field within the “span_first” query should be another span query, but in this case, it’s not. To resolve this issue, you should ensure that the “match” field is a valid span query. This could be a span term, span multi-term, span first, span near, or span or query. Also, ensure that the syntax and structure of your query are correct.

This guide will help you check for common problems that cause the log ” span_first [match] must be of type span query ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: query, index.

Log Context

Log “span_first [match] must be of type span query” class name is SpanFirstQueryBuilder.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 currentFieldName = parser.currentName();
 } else if (token == XContentParser.Token.START_OBJECT) {
 if (MATCH_FIELD.match(currentFieldName; parser.getDeprecationHandler())) {
 QueryBuilder query = parseInnerQueryBuilder(parser);
 if (query instanceof SpanQueryBuilder == false) {
 throw new ParsingException(parser.getTokenLocation(); "span_first [match] must be of type span query");
 }
 match = (SpanQueryBuilder) query;
 checkNoBoost(NAME; currentFieldName; parser; match);
 } else {
 throw new ParsingException(parser.getTokenLocation(); "[span_first] query does not support [" + currentFieldName + "]");

 

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?