# SpanOrQuery Problem

**URL:** <https://discuss.elastic.co/t/spanorquery-problem/75682>\
**Category:** Elasticsearch\
**Created:** [February 20, 2017, 7:29am UTC](https://discuss.elastic.co/t/spanorquery-problem/75682 "2017-02-20T07:29:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumirian](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sumirian](https://discuss.elastic.co/u/sumirian)\
**Post date:** [February 20, 2017, 7:29am UTC](https://discuss.elastic.co/t/spanorquery-problem/75682/1 "2017-02-20T07:29:03Z")

</div>

I have a field (navigation.path) using whitespace analyzer to analyze.

When the value is "P1 P2 P3 P4 P5",  
I hope the query which has the meaning similar to P1 (slop 5) (P2 or P4) (slop 0) P5 can match it. It failed.  
I use P1 (slop 5) P4 (slop 0) P5, and it matched.

Here is my confuse. When using the spanOrQuery, is elasticsearch just match one condition and continue to match remaining query, and will not go back to match other span or conditions even the previous match failed?  
If it is true, is the spanOrQuery can only be the last item in span queries?

Below is my query dsl.  
{  
"span\_near" : {  
"clauses" : [ {  
"span\_near" : {  
"clauses" : [ {  
"span\_or" : {  
"clauses" : [ {  
"span\_term" : {  
"navigation.path" : {  
"value" : "P1"  
}  
}  
} ]  
}  
}, {  
"span\_first" : {  
"match" : {  
"span\_or" : {  
"clauses" : [ {  
"span\_term" : {  
"navigation.path" : {  
"value" : "P4"  
}  
}  
}, {  
"span\_term" : {  
"navigation.path" : {  
"value" : "P2"  
}  
}  
} ]  
}  
},  
"end" : 10  
}  
} ],  
"slop" : 5,  
"in\_order" : true  
}  
}, {  
"span\_or" : {  
"clauses" : [ {  
"span\_term" : {  
"navigation.path" : {  
"value" : "P5"  
}  
}  
} ]  
}  
} ],  
"slop" : 0,  
"in\_order" : true  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 20, 2017, 7:29am UTC](https://discuss.elastic.co/t/spanorquery-problem/75682/2 "2017-03-20T07:29:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
