Span First Query

More info about Span First query is in the official elasticsearch docs

Matches spans near the beginning of a field. The span first query maps to Lucene SpanFirstQuery. Here is an example:

{
    "query": {
        "span_first" : {
            "match" : {
                "span_term" : { "user" : "kimchy" }
            },
            "end" : 3
        }
    }
}

And now the query via DSL:

$search = new Search();
$query = new SpanFirstQuery(new SpanTermQuery('user', 'kimchy'), 3);
$search->addQuery($query);

$search->toArray();