Search with phonetic plugin, Elasticsearch-7.6.1

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

{
  "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

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

Output

{
    "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

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

Search return is empty

GET /phonetic_sample/_doc/_search

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

Please let me know what is wrong?

Welcome!

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

Try this:

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"
      }
    }
  }
}

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?

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

HTH

Thank you, it is really helpful!

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