Advanced Search - JulianThijssen/TelegraafES GitHub Wiki
Advanced Search
To allow for advanced search we change the query from the relatively simple:
{
'query': {
'bool': {
'should': {
'match': {
'text': {
'query': $text,
'operator': 'and'
}
}
}
}
}
}
to a more complex query that matches in both the title and text of the document. To give titles a little bit more importance we double its importance in the ranking.
{
'query': {
'bool': {
'should': {
'match': {
'title': {
'query': $title,
'operator': 'and',
'boost': 2
}
}
'match': {
'text': {
'query': $text,
'operator': 'and',
'boost': 1
}
}
}
}
}
}
Note that the query is still quite flexible in its matching as the boolean function is 'should' which in contrast to 'must' does not necessarily need the query terms to be in either the title or text.
By using this query format we allow the user to search for a document that has title XXX and contains the terms YYY in the text. We do not find that changing 'should' to 'must' makes the ranked results any better as can be seen in the final evaluation.