# Search with phonetic plugin, Elasticsearch-7.6.1

**URL:** <https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950>\
**Category:** Elasticsearch\
**Created:** [March 17, 2020, 2:33pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950 "2020-03-17T14:33:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobflip](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bobflip](https://discuss.elastic.co/u/bobflip)\
**Post date:** [March 17, 2020, 2:33pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/1 "2020-03-17T14:33:17Z")

</div>

Hi, I'm trying to search with analysis-phonetic plugin and cannot get matching results. Please help!  
I've installed plugin, and took example from documentation

**PUT /phonetic\_sample**

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

```

**GET /phonetic\_sample/\_analyze is working fine**

```auto
{
  "analyzer": "my_analyzer",
  "text": "lopez" 
}

```

Output

```auto
{
    "tokens": [
        {
            "token": "LPS",
            "start_offset": 0,
            "end_offset": 5,
            "type": "<ALPHANUM>",
            "position": 0
        },
        {
            "token": "lopez",
            "start_offset": 0,
            "end_offset": 5,
            "type": "<ALPHANUM>",
            "position": 0
        }
    ]
}

```

Added a document

**PUT /phonetic\_sample/\_doc/1**

```auto
{"firstname": "cindy",
"lastname": "lopes"
}

```

Search return is empty

**GET /phonetic\_sample/\_doc/\_search**

```auto
    "query": {
        "match": {
            "lastname": {
                "query": "lopez",
                "analyzer": "my_analyzer" 
            }
        }
    }
}

```

Please let me know what is wrong?

---

<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 17, 2020, 3:16pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/2 "2020-03-17T15:16:47Z")

</div>

Welcome!

You should define the analyzer in the mapping. In fact you should define a mapping.

Try this:

```auto
DELETE /phonetic_sample
PUT /phonetic_sample
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "my_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "my_metaphone"
            ]
          }
        },
        "filter": {
          "my_metaphone": {
            "type": "phonetic",
            "encoder": "metaphone",
            "replace": false
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "firstname": {
        "type": "text",
        "analyzer": "my_analyzer"
      },
      "lastname": {
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}
PUT /phonetic_sample/_doc/1
{
  "firstname": "cindy",
  "lastname": "lopes"
}
GET /phonetic_sample/_search
{
  "query": {
    "match": {
      "lastname": {
        "query": "lopez"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![bobflip](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bobflip](https://discuss.elastic.co/u/bobflip)\
**Post date:** [March 17, 2020, 3:29pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/3 "2020-03-17T15:29:03Z")

</div>

Thank you! It works now. Can you please advise how I can search same field with different analyzers like phonetic and synonym if explicit mapping of analyzer is needed?

---

<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 17, 2020, 4:02pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/4 "2020-03-17T16:02:13Z")

</div>

Not the exact answer but you can get some ideas from this script:

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

HTH

---

<div class="post-metadata">

**Author:** ![bobflip](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bobflip](https://discuss.elastic.co/u/bobflip)\
**Post date:** [March 18, 2020, 1:41pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/5 "2020-03-18T13:41:34Z")

</div>

Thank you, it is really helpful!

---

<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 15, 2020, 1:44pm UTC](https://discuss.elastic.co/t/search-with-phonetic-plugin-elasticsearch-7-6-1/223950/6 "2020-04-15T13:44:46Z")

</div>

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