Combining Text Query and Span Query?


(quain) #1

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
}
}
]
}
},


(system) #2