Switching Service from Elasticsearch to Typesense
TLDR Sebastian inquires about recreating Elasticsearch Boolean Queries in Typesense. Jason explains that Typesense behaves as should
by default and suggests configuring specific must
keywords with double quotes.
Aug 09, 2023 (4 months ago)
Sebastian
04: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.html
Jason
05: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
05:53 PMshould
. The dropping of keywords I mentioned above happens left to right, then right to leftYou can configure which keywords should be
must
by surrounding them with double quotesSebastian
09:50 PMSebastian
09:50 PMTypesense
Indexed 3015 threads (79% resolved)
Similar Threads
Phrase Search Relevancy and Weights Fix
Jan reported an issue with phrase search relevancy using Typesense Instantsearch Adapter. The problem occurred when searching phrases with double quotes. The team identified the issue to be related to weights and implemented a fix, improving the search results.
Docsearch Scrapper Metadata Configuration and Filter Problem
Marcos faced issues with Docsearch scrapper not adding metadata attributes and filtering out documents without content. Jason helped fix the issue by updating the scraper and providing filtering instructions.
Sorting Results in Typesense and Handling Errors
Ramees asks about sorting results by distance in Typesense, entering a list of strings as a field, and resolving an error with `fields` format. Kishore Nallan assists with these issues and advises on storing timestamps and proper authentication.