# How to use phonetic analyzer using AWS Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008>\
**Category:** Elasticsearch\
**Created:** [February 5, 2020, 2:30pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008 "2020-02-05T14:30:47Z")\
**Posts on this page:** 10\
**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:** [February 5, 2020, 2:30pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/1 "2020-02-05T14:30:47Z")

</div>

I am currently using AWS Elasticsearch. Currently making the following query to search for the data:

```auto
{
    "query": {
        "multi_match" : {
            "query" : "murder",
            "fields" : ["content", "title^10"],
            "fuzziness" : "AUTO"
        }
    },
     "size": "10",

     "_source": ["title", "bench", "court"],
     "highlight": {
        "fields" : {
            "title" : {},
            "content":{}
        }
    }

}

```

How can I incorporate phonetic analysis into this? If possible, I would also like to incoporate synonym search into the above query

---

<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:** [February 5, 2020, 3:36pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/2 "2020-02-05T15:36:20Z")

</div>

> [@abhijith\_chandran](#):
>
> How can I incorporate phonetic analysis into this?

You'd need the phonetic plugin. See [Phonetic analysis plugin | Elasticsearch Plugins and Integrations [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-phonetic.html)

> [@abhijith\_chandran](#):
>
> If possible, I would also like to incoporate synonym search into the above query

Have a look at [Synonym graph token filter | Elasticsearch Guide [7.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/analysis-synonym-graph-tokenfilter.html)

BTW did you look at [Elastic Cloud: Hosted Elasticsearch, Hosted Search | Elastic](https://www.elastic.co/cloud) and [https://aws.amazon.com/marketplace/pp/B01N6YCISK](https://aws.amazon.com/marketplace/pp/B01N6YCISK) ?

Cloud by elastic is one way to have access to all features, all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, APM, Logs UI, Infra UI, SIEM, Maps UI and what is coming next 🙂 ...

---

<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:** [February 5, 2020, 4:44pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/3 "2020-02-05T16:44:04Z")

</div>

Using the built-in plugin in AWS - [https://aws.amazon.com/about-aws/whats-new/2016/12/amazon-elasticsearch-service-now-supports-phonetic-analysis/](https://aws.amazon.com/about-aws/whats-new/2016/12/amazon-elasticsearch-service-now-supports-phonetic-analysis/).

Before indexing, I used this code to set up the phonetic analyzer.

```auto
PUT enpoint/courts_2
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "my_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "my_metaphone"
            ]
          }
        },
        "filter": {
          "my_metaphone": {
            "type": "phonetic",
            "encoder": "metaphone",
            "replace": true
          }
        }
      }
    }
  }
}

```

Note: I have not downloaded it specifically as AWS has it pre-built (Check above link).  
Now,  
I am using this code to make the query to the endpoint -

```auto
{
    "query": {
        "multi_match" : {
            "query" : "Abhijith",
            "fields" : ["content", "title^10"],
             "analyzer": "my_analyzer"

        }
    },
     "size": "1",
     "_source": ["title", "bench", "court"],
     "highlight": {
        "fields" : {
            "title" : {},
            "content":{}
        }
    }

}

```

But I am getting zero results back. I am getting the below output:

```auto
{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

```

I can confirm that when not using the analyzer, I am getting back hits.

When I use this code, it returns normal output though.

```auto
GET courts_2/_analyze
{
  "analyzer": "my_analyzer",
  "text": "Abhijith"
}

```

**Response**

```auto
{
    "tokens": [
        {
            "token": "ABHJ",
            "start_offset": 0,
            "end_offset": 8,
            "type": "<ALPHANUM>",
            "position": 0
        }
    ]
}

```

---

<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:** [February 5, 2020, 4:57pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/4 "2020-02-05T16:57:27Z")

</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:** ![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:** [February 5, 2020, 5:04pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/5 "2020-02-05T17:04:44Z")

</div>

Hi,  
I have edited the above post with all the details. It would be great if you could look in:) @dadoonet

---

<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:** [February 27, 2020, 9:33am UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/6 "2020-02-27T09:33:27Z")

</div>

I'm still missing a way to reproduce the problem.  
Could you share a full script as per the example provided in the link I gave you?

If I run your query I won't get any hit as nothing has been indexed.

---

<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:** [February 27, 2020, 1:07pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/7 "2020-02-27T13:07:07Z")

</div>

Hi @dadoonet, I have solved the above problem already. I have a new problem, and if you could look into it that would be great.

> [@Incoporating search with Boolean Queries?](https://discuss.elastic.co/t/incoporating-search-with-boolean-queries/220649):
>
> Hi, I am currently using the following query - { "\_source": ["title", "bench", "id\_", "court", "date", "content"], "size": 15, "from": 0, "query": { "bool": { "must": [{ "multi\_match": { "query": "the", "fields": ["content"], "operator": "a…

---

<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:** [February 27, 2020, 1:19pm UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/8 "2020-02-27T13:19:20Z")

</div>

That'd be great to add an answer to this thread with your solution so it can be shared with the community.

---

<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:** [February 29, 2020, 10:46am UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/9 "2020-02-29T10:46:46Z")

</div>

Here is how I did it:  
I used the metaphone analyzer and used the following code to set the analyzer (Note: On AWS, I had to reindex the data:(

```auto
PUT 
{
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "my_analyzer": {
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "my_metaphone"
                        ]
                    }
                },
                "filter": {
                    "my_metaphone": {
                        "type": "phonetic",
                        "encoder": "metaphone",
                        "replace": true
                    }
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "author": {
                "type": "text",
                "analyzer": "my_analyzer"
            },
            "bench": {
                "type": "text",
                "analyzer": "my_analyzer"
            },
            "citation": {
                "type": "text"
            },
            "court": {
                "type": "text"
            },
            "date": {
                "type": "text"
            },
            "id_": {
                "type": "text"
            },
            "verdict": {
                "type": "text"
            },
            "title": {
                "type": "text",
                "analyzer": "my_analyzer",
                "fields": {
                    "standard": {
                        "type": "text"
                    }
                }
            },
            "content": {
                "type": "text",
                "analyzer": "my_analyzer",
                "fields": {
                    "standard": {
                        "type": "text"
                    }
                }
            }
        }
    }
}

```

Now, you can query your index with the phonetic analyzer. Note: The phonetic analyzer will be the default now, to use the standard one use `titile.standard` (example.)

---

<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:** [March 28, 2020, 10:46am UTC](https://discuss.elastic.co/t/how-to-use-phonetic-analyzer-using-aws-elasticsearch/218008/10 "2020-03-28T10:46:50Z")

</div>

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