# Using span query for different fields - i.e., this field or that field for span query

**URL:** <https://discuss.elastic.co/t/using-span-query-for-different-fields-i-e-this-field-or-that-field-for-span-query/78531>\
**Category:** Elasticsearch\
**Created:** [March 14, 2017, 1:56pm UTC](https://discuss.elastic.co/t/using-span-query-for-different-fields-i-e-this-field-or-that-field-for-span-query/78531 "2017-03-14T13:56:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Steiner](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@David\_Steiner](https://discuss.elastic.co/u/David_Steiner)\
**Post date:** [March 14, 2017, 1:56pm UTC](https://discuss.elastic.co/t/using-span-query-for-different-fields-i-e-this-field-or-that-field-for-span-query/78531/1 "2017-03-14T13:56:21Z")

</div>

I think I've figured out how to search for a particular user query using span, except I'd like to run an OR query for the stemmed and non-stemmed version of the field.  
The query I'm trying to satisfy is: phraseWord1 phraseWord2 /50 (word1 OR word2).  
So, I can search the non-stemmed (or stemmed) field doing this:  
{  
"span\_near" : {  
"clauses" : [  
{  
"span\_near" : {  
"clauses" : [  
{ "span\_term" : { "field" : "phraseWord1" } },  
{ "span\_term" : { "field" : "phraseWord2" } }  
],  
"slop" : 0,  
"in\_order" : true  
}  
},  
{  
"span\_or" : {  
"clauses" : [  
{ "span\_term" : { "field" : "word1" } },  
{ "span\_term" : { "field" : "word2" } }  
]  
}  
}  
],  
"slop" : 50,  
"in\_order" : false  
}  
}

However, I can't figure out how to OR this with the exact same span query for "field.stemmed" instead of "field". I tried to use "span\_or" for this, but apparently it wouldn't let me combine the two queries (one in "field" and the other in "field.stemmed") because I get an error saying that:  
"caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "Clauses must have same field."

Thanks for any direction, I'd appreciate it... Still learning...

---

<div class="post-metadata">

**Author:** ![David\_Steiner](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@David\_Steiner](https://discuss.elastic.co/u/David_Steiner)\
**Post date:** [March 15, 2017, 2:34pm UTC](https://discuss.elastic.co/t/using-span-query-for-different-fields-i-e-this-field-or-that-field-for-span-query/78531/2 "2017-03-15T14:34:10Z")

</div>

I think I figured it out using field\_masking\_span. Let me know if that's not what I should use...

{  
"span\_or" : {  
"clauses" : [  
{  
"span\_near" : {  
"clauses" : [  
{  
"span\_near" : {  
"clauses" : [  
{ "span\_term" : { "doc.body" : "ipse" } },  
{ "span\_term" : { "doc.body" : "dixit" } }  
],  
"slop" : 0,  
"in\_order" : true  
}  
},  
{  
"span\_or" : {  
"clauses" : [  
{ "span\_term" : { "doc.body" : "clear" } },  
{ "span\_term" : { "doc.body" : "clearly" } }  
]  
}  
}  
],  
"slop" : 50,  
"in\_order" : false  
}  
},  
{  
"field\_masking\_span": {  
"query":  
{  
"span\_near" : {  
"clauses" : [  
{  
"field\_masking\_span": {  
"query":  
{  
"span\_near" : {  
"clauses" : [  
{ "span\_term" : { "doc.body.stemmed" : "ipse" } },  
{ "span\_term" : { "doc.body.stemmed" : "dixit" } }  
],  
"slop" : 0,  
"in\_order" : true  
}  
},  
"field": "doc.body"  
}  
},  
{  
"field\_masking\_span": {  
"query":  
{  
"span\_or" : {  
"clauses" : [  
{ "span\_term" : { "doc.body.stemmed" : "clear" } },  
{ "span\_term" : { "doc.body.stemmed" : "clearly" } }  
]  
}  
},  
"field": "doc.body"  
}  
}],  
"slop" : 50,  
"in\_order" : false  
}  
},  
"field": "doc.body"  
}  
}]  
}  
}

---

<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:** [April 12, 2017, 2:34pm UTC](https://discuss.elastic.co/t/using-span-query-for-different-fields-i-e-this-field-or-that-field-for-span-query/78531/3 "2017-04-12T14:34:11Z")

</div>

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