ElasticSearch - search using abbreviations

I'm trying to set up an existing / custom parser that allows searching using abbreviations. For example, if the text box is "Bank Of America", search for BOfA or BOA, BofA, etc. Must match this entry.

How can i do this? Please help.

+3


source to share


1 answer


You can use a synonym token for a custom parser.

For example, the following displays

{
"settings": {
    "analysis": {
        "analyzer": {
            "my_analyzer": {
                "tokenizer": "standard",
                "filter": ["lowercase", "synonym_filter"]
            }
        },
        "filter": {
            "synonym_filter": {
                "type": "synonym",
                "synonyms": [
                    "bank of america,boa"
                ],
                "expand": true
            }
        }
    }
},
"mappings": {
    "document": {
        "properties": {
            "text": {
                "type": "text",
                "analyzer": "my_analyzer",
                "fielddata": true
            }
        }
    }
}

      

}

You can definitely add more to the list or use a synonym file.

For usecases requests BOfA or BOA, BofA - two approaches can be used.



1) More synonyms with this possible combination

 "synonyms": [
                    "bank of america,boa"
                    "bank of america,bofa"
                ]

      

2) or keep abbreviations intact and use fuzzy query

{
  "query": {
    "match": {
      "text" : {
        "query": "bofa",
        "fuzziness": 2
      }
    }
  }
}

      

You will need synonyms to provide ES abbreviations.

0


source







All Articles