Hi! We want to switch a service that uses Elastics...
# community-help
s
Hi! We want to switch a service that uses Elasticsearch Boolean Queries to Typesense. Is it possible to build something similar to the query below in Typesense? We can use filters for
must
and
must_not
sections. What would be the best way to write
should
queries and to
boost
some elements of the query over others?
Copy code
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
j
should
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.
But it’s not possible to specifically indicate which specific keywords are
should
. 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 quotes
s
Thank you @Jason Bosco!
Cc @Rushil Srivastava