Sebastian Bastidas
08/09/2023, 4:12 PMmust
and must_not
sections.
What would be the best way to write should
queries and to boost
some elements of the query over others?
POST _search
{
"query": {
"bool" : {
"must" : {
"term" : { "user.id" : "kimchy" },
"boost": 20
},
"filter": {
"term" : { "tags" : "production" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 },
"boost":5
}
},
"should" : [
{ "term" : { "tags" : "env1" } },
{ "term" : { "tags" : "deployed" } }
],
"minimum_should_match" : 1,
"boost" : 1.0
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.htmlJason Bosco
08/09/2023, 5:52 PMshould
is how Typesense behaves by default. It will first look for all terms in the query in the same record, if it doesn’t find enough records (threshold defined by drop_tokens_threshold
), it will drop keywords until enough matches are found.Jason Bosco
08/09/2023, 5:53 PMshould
. The dropping of keywords I mentioned above happens left to right, then right to left
You can configure which keywords should be must
by surrounding them with double quotesSebastian Bastidas
08/09/2023, 9:50 PMSebastian Bastidas
08/09/2023, 9:50 PM