This is a search page that's expecting a good deal of requests, so I'm trying to minimize executed queries while also trying to represent relevant results.
In this search system, most people will be looking up exact matches, usually via copy and paste from a different source. But there is the occasional generic search based on a term. I want to cater to both audiences.
So right now, I have
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"name" : "{searchterm}"
}
}
}
}
}
the mappings for the "name" field has been set as not_analyzed with this (using php):
'mappings' => [
$type => [
'properties' => [
'name' => [
'type' => 'string',
'index' => 'not_analyzed'
]
]
]
]
and so far, that's gravy.
I'd like to now update the actual query to fall back to a second field, that allows the analyzer to do it's thing in full.
Additionally, is there a way to group the results (kind of like the highlighter) so elasticsearch can tell me if there was an exact hit with the name field? if not that's fine too, on the software level I can just compare the top result to the search term, but it would be nice to have an elegant solution here
Thank you!