# Combining Text Query and Span Query?

**URL:** <https://discuss.elastic.co/t/combining-text-query-and-span-query/6611>\
**Category:** Elasticsearch\
**Created:** [February 7, 2012, 1:18am UTC](https://discuss.elastic.co/t/combining-text-query-and-span-query/6611 "2012-02-07T01:18:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quain/32/2925_2.png) [@quain](https://discuss.elastic.co/u/quain)\
**Post date:** [February 7, 2012, 1:18am UTC](https://discuss.elastic.co/t/combining-text-query-and-span-query/6611/1 "2012-02-07T01:18:03Z")

</div>

I'm trying to make an autocomplete search, using text query with  
phrase\_prefix. But I want to prioritize results which start with the  
query before all other matches.

For example: for a search of "quick brown", prefer "quick brown fox",  
over "fox is quick brown".

I ended up using a dix\_max, with a text phrase\_prefix match as one  
query, and a span\_first as the other subquery and boosting it. Is  
this a good solution? One concern is that I think text query is  
analyzed, but span query is not analyzed, this will be a problem  
right? Any suggestions either using this approach or a better one is  
greatly appreciated!

query: {  
"dis\_max": {  
"queries":[  
{  
"text": {  
"name": {  
"query": q,  
"type": "phrase\_prefix" ,  
"slop": "1"  
}  
}  
},  
{  
"span\_first": {  
"match": {  
"span\_term": q}  
},  
"boost": 2.0,  
"end": 1  
}  
}  
]  
}  
},

---

<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:** [July 6, 2017, 3:40am UTC](https://discuss.elastic.co/t/combining-text-query-and-span-query/6611/2 "2017-07-06T03:40:26Z")

</div>


