# Exact search getting less precedence then phonetic?

**URL:** <https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485>\
**Category:** Elasticsearch\
**Created:** [April 17, 2020, 9:49am UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485 "2020-04-17T09:49:25Z")\
**Posts on this page:** 5\
**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:** [April 17, 2020, 9:49am UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485/1 "2020-04-17T09:49:25Z")

</div>

I have an elasticsearch index and am using the following query:

```auto
    "_source": [
        "title", 
        "content"

    ],
    "size": 15,
    "from": 0,
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "{{query}}",
                    "fields": [
                        "title",
                        "content"
                    ],
                    "operator": "or"
                }
            },
            "should": [
                {
                    "multi_match": {
                        "query": "{{query}}",
                        "fields": [
                            "title.standard^16",
                            "content.standard^2"
                        ],
                        "operator": "and"
                    }
                },
                {
                    "match_phrase": {
                        "content.standard": {
                            "query": "{{query}}",
                            "_name": "Phrase on title",
                            "boost": 1000
                        }
                    }
                }
            ]
        }
    },
    "highlight": {

        "fields": {
            "content": {}
        },
        "fragment_size": 100
    }
}

```

Here is the mapping I set:

```auto
{
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "my_analyzer": {
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "my_metaphone"
                        ]
                    }
                },
                "filter": {
                    "my_metaphone": {
                        "type": "phonetic",
                        "encoder": "metaphone",
                        "replace": true
                    }
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "title": {
                "type": "text",
                "term_vector": "with_positions_offsets",
                "analyzer": "my_analyzer",
                "fields": {
                    "standard": {
                        "type": "text"
                    }, 
                    "stemmer": {
                        "type": "text", 
                        "analyzer": "english"  
                    }
                }
            },
            "content": {
                "type": "text",
                "term_vector": "with_positions_offsets",
                "analyzer": "my_analyzer",
                "fields": {
                    "standard": {
                        "type": "text"
                    }, 
                    "stemmer": {
                        "type": "text", 
                        "analyzer": "english"  
                    }
                }
            }
        }
    }
}

```

Here is my logic with the query:

1. It will give the highest precedence to a phrase if it appears.

2. If not it will use the standard analyzer (that is the text, as is) and give it the highest precedence.

3. If all else doesn't match up, it will use the phonetic analyzer to get the results, that is the least precedence.

But obviously there is some fault to this as it seems to give higher precedence to the phonetic analyzer than the standard or phrase. For example, if I search for "Person of Indian Origin" it returns results on the top highlighting "Pursuant" "pursuing" and very, very less number of results with person of Indian origin although I know a large number of them exists. How do I solve this?

Here is some sample data to test it out - [https://pastebin.com/mzfwz0b3](https://pastebin.com/mzfwz0b3)

---

<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:** [April 17, 2020, 10:31am UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485/2 "2020-04-17T10:31:04Z")

</div>

You can combine multiple searches within a `bool` query in `should` clauses.  
I have an example here which might help:

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

---

<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:** [April 17, 2020, 11:49am UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485/3 "2020-04-17T11:49:58Z")

</div>

Hi @dadoonet I did try this out but did not get desired results. Having a bunch if should statements and then boosting them did not work well.

---

<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:** [April 17, 2020, 12:13pm UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485/4 "2020-04-17T12:13:38Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [May 15, 2020, 12:13pm UTC](https://discuss.elastic.co/t/exact-search-getting-less-precedence-then-phonetic/228485/5 "2020-05-15T12:13:48Z")

</div>

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