# How to give different weights to exact, phonetic and fuzzy queries?

**URL:** https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365
**Category:** Elasticsearch
**Created:** [March 20, 2020, 7:32am UTC](https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365 "2020-03-20T07:32:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![abhijith\_chandran](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhijith_chandran/32/60470_2.png) [@abhijith\_chandran](https://discuss.elastic.co/u/abhijith_chandran)
#### Post date: [March 20, 2020, 7:32am UTC](https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365/1 "2020-03-20T07:32:16Z")

</div>

Hi,  
So currently I am using the following query:

```auto
{
    "_source": [
        "title",
        "bench",
        "id_",
        "court",
        "date"
    ],
    "size": 15,
    "from": 0,
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "knife",
                    "fields": [
                        "title",
                        "body"
                      
                    ],
                    "operator": "and"
                }
            },
            "should": {
                "multi_match": {
                    "query": "knife",
                    "fields": [
                        "title",
                        "body"
                    ],
                    "fuzziness" : 1,
                    "operator": "and"
                }
            }
        }
    },
    "highlight": {
        "pre_tags": [
            "<tag1>"
        ],
        "post_tags": [
            "</tag1>"
        ],
        "fields": {
            "content": {}
        },
        "fragment_size": 30
    }
}

```

What I want to achieve is that I want to give different weights to exact, phonetic and fuzy queries in the order exact \> fuzzy \> phonetic. How do I acheive this?

This is my mapping - (My analyzer is a Metaphone analyzer)

```auto
{
    "courts_2": {
        "mappings": {
            "properties": {
                "author": {
                    "type": "text",
                    "analyzer": "my_analyzer"
                },
                "bench": {
                    "type": "text",
                    "analyzer": "my_analyzer"
                },
                "citation": {
                    "type": "text"
                },
                "content": {
                    "type": "text",
                    "fields": {
                        "standard": {
                            "type": "text"
                        }
                    },
                    "analyzer": "my_analyzer"
                },
                "court": {
                    "type": "text"
                },
                "date": {
                    "type": "text"
                },
                "id_": {
                    "type": "text"
                },
                "title": {
                    "type": "text",
                    "fields": {
                        "standard": {
                            "type": "text"
                        }
                    },
                    "analyzer": "my_analyzer"
                },
                "verdict": {
                    "type": "text"
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 20, 2020, 8:47am UTC](https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365/2 "2020-03-20T08:47:46Z")

</div>

I shared a script here which can gives you some ideas.

> <https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab>

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 22, 2020, 9:37am UTC](https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365/4 "2020-03-22T09:37:59Z")

</div>

It will use the analyzer you defined for the `title` field.

---

<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: [April 19, 2020, 9:48am UTC](https://discuss.elastic.co/t/how-to-give-different-weights-to-exact-phonetic-and-fuzzy-queries/224365/5 "2020-04-19T09:48:36Z")

</div>

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