Phrase suggest with analysis-phonetic plugin in Elasticsearch 5.5

Hey! I'm developing a search feature in a web app, and I'm using Elasticsearch 5.5.3 (I can't use newer versions, 5.5.3 was a requirement from the client).

I'm also using the phrase suggest feature. Right now it only searches on the given string, but if a suggest string it's available, it replaces the search with the suggested string (basically it doesn't include other strings in the search).

The thing is, I'm trying to use the analysis-phonetic plugin to suggest similar strings with similar sounding words (for example, if someone searches "Shile" it should suggest "Chile" because they sound the same in Spanish). But what I've done so far doesn't work.

Here's the mapping I had before trying to implement it (I'm including the analyzer I created for this though, 'metaphone_analyzer'):

{
    "searches": {
        "aliases": {},
        "mappings": {
            "document": {
                "properties": {
                    "description": {
                        "type": "text",
                        "store": true
                    },
                    "detail": {
                        "type": "text",
                        "store": true,
                        "copy_to": [
                            "suggest_field"
                        ]
                    },
                    "language_code": {
                        "type": "text"
                    },
                    "name": {
                        "type": "text",
                        "store": true,
                        "copy_to": [
                            "suggest_field"
                        ]
                    },
                    "suggest_field": {
                        "type": "text"
                    },
                    "title": {
                        "type": "text",
                        "store": true,
                        "copy_to": [
                            "suggest_field"
                        ]
                    }
                }
            }
        },
        "settings": {
            "index": {
                "number_of_shards": "5",
                "provided_name": "searches",
                "creation_date": "1532112095449",
                "analysis": {
                    "filter": {
                        "shingle_filter": {
                            "max_shingle_size": "3",
                            "min_shingle_size": "2",
                            "type": "shingle"
                        },
                        "dbl_metaphone": {
                            "type": "phonetic",
                            "encoder": "double_metaphone"
                        },
                        "es_filter": {
                            "type": "stop",
                            "stopwords": "_spanish_"
                        },
                        "en_filter": {
                            "type": "stop",
                            "stopwords": "_english_"
                        }
                    },
                    "analyzer": {
                        "default": {
                            "filter": [
                                "lowercase",
                                "asciifolding",
                                "shingle_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        },
                        "en_analyzer": {
                            "filter": [
                                "lowercase",
                                "asciifolding",
                                "en_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        },
                        "es_analyzer": {
                            "filter": [
                                "lowercase",
                                "asciifolding",
                                "es_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        },
                        "metaphone_analyzer": {
                            "filter": [
                                "lowercase",
                                "asciifolding",
                                "shingle_filter",
                                "dbl_metaphone"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "SDykW954Q3egFIJEi1aA5w",
                "version": {
                    "created": "5050399"
                }
            }
        }
    }
}

And here's my query:

{
    "suggest": {
        "suggestion": {
            "text": "search text",
            "phrase": {
                "max_errors": 2,
                "field": "suggest_field",
                "direct_generator": [
                    {
                        "suggest_mode": "missing",
                        "field": "suggest_field"
                    }
                ],
                "gram_size": 3,
                "size": 1,
                "highlight": {
                    "pre_tag": "<strong>",
                    "post_tag": "</strong>"
                }
            }
        }
    },
    "highlight": {
        ...
    },
    "query": {
        ...
    }
}

Basically I copy some fields to the field 'suggest_field', so I can use suggest on a bunch of fields at once.

So, any ideas or a direction I should be heading?

Thanks.

PS: Just for the record, it's a Django web app, and I'm using elasticsearch-dsl, but I'm writing the final queries here for simplicity.

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