title: Maintain sequence order for match phrase query with slop in Elasticsearch Java API
body: <p>I am trying to do a query which should be similar to the phrase query except that there can be gaps within consecutive tokens. Example:</p>
  
  <pre><code>Document: "a b c d"
  Search: "a c" &gt;&gt; This should return the document,
  Search: "c a" &gt;&gt; This should not return the document.
  </code></pre>
  
  <p>Phrase query ensures that the order will remain only when no slop value is being used. Once I add some slop value (2, 3 etc), it starts to break order, and with sufficiently large slop value, it will probably just be as normal match query as mentioned in elasticsearch documentation. </p>
  
  <p>Note, I am using the AND operator, hence all the search tokens must be present.</p>
  
  <p>Is it possible to do queries like this in Elasticsearch?</p>
  
  <p>[EDIT]
  As for being marked as duplicate to <a href="https://stackoverflow.com/questions/34452808/analyze-and-match-all-terms-in-same-order">this</a> question, I am using spring-data-elasticsearch for my project and the stack overflow question does not have an answer that is related to spring-data elasticsearch java-api (ElasticsearchTemplate preferably).</p>