Elasticsearch Query Template Help - Wildcard and Fuzzy

Hey Guys!

I'll need some help - we are trying to build a search system. And we have a few business rules.

Right now, our search template is looking like this:

GET web-shop-0/_search
{
"query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "name": {
              "value": "{{query}}*",
            }
          }
        },
        {
          "fuzzy": {
            "name": {
              "value": "{{query}}",
              "fuzziness": 2,
            }
          }
        }
      ]
    }
  }
}

The problem is:

  • When searching by "submarine" it returns fine...
  • However, when we do by "submarin" it returns something like:
    • "mini submarine"
    • "maxi submarine"
    • "submarine"

Our goal is to result always first the submarine, so it should be always the first word...

Not sure if I was very clear, but please let me know.

Tnx!

you can use
GET web-shop-0/_search?explain=true
to check the score of the matched documents.and you will see that the wildcard query give the score 1; the fuzzy query give another score, the sum of scores will be the final score. so the important part of the score is fuzzy query.
in the fuzzy query, tf, idf, norms will affect the score.
sometimes the score will be influenced by the quantity of documents in every shard, if your documents is few and not well-distributed in every shard, something unexpected will happen.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.