# Elasticsearch Query Template Help - Wildcard and Fuzzy

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-template-help-wildcard-and-fuzzy/161211>\
**Category:** Elasticsearch\
**Created:** [December 17, 2018, 9:18pm UTC](https://discuss.elastic.co/t/elasticsearch-query-template-help-wildcard-and-fuzzy/161211 "2018-12-17T21:18:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiagoverissimo](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@tiagoverissimo](https://discuss.elastic.co/u/tiagoverissimo)\
**Post date:** [December 17, 2018, 9:18pm UTC](https://discuss.elastic.co/t/elasticsearch-query-template-help-wildcard-and-fuzzy/161211/1 "2018-12-17T21:18:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zz\_hello](https://avatars.discourse-cdn.com/v4/letter/z/3bc359/32.png) [@zz\_hello](https://discuss.elastic.co/u/zz_hello)\
**Post date:** [December 18, 2018, 5:44am UTC](https://discuss.elastic.co/t/elasticsearch-query-template-help-wildcard-and-fuzzy/161211/2 "2018-12-18T05:44:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 15, 2019, 5:50am UTC](https://discuss.elastic.co/t/elasticsearch-query-template-help-wildcard-and-fuzzy/161211/3 "2019-01-15T05:50:05Z")

</div>

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