# Product title autocompletion/suggestions

**URL:** https://discuss.elastic.co/t/product-title-autocompletion-suggestions/271949
**Category:** Elasticsearch
**Created:** [May 3, 2021, 8:59am UTC](https://discuss.elastic.co/t/product-title-autocompletion-suggestions/271949 "2021-05-03T08:59:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![corlee](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@corlee](https://discuss.elastic.co/u/corlee)
#### Post date: [May 3, 2021, 8:59am UTC](https://discuss.elastic.co/t/product-title-autocompletion-suggestions/271949/1 "2021-05-03T08:59:56Z")

</div>

Hi there,

I'm currently struggling with autocompletion/suggestions. I've got a product database with a title, description, price, etc.

What i want to achieve is for example:

Example: When i search for "ipad", I want to show the following items in a suggestion dropdown:

- Apple **iPad**
- Apple 64GB Wifi + 4G (Blauw) **iPad** Air (2020)
- Apple 11-inch **iPad** Pro (2021) Wi‑Fi

I've tried the completion suggester, which works fine if you know the whole product name because it's suggest from the beginning of the product name..

Now I'm trying a phrase suggester, with the following mapping/config:

```
'settings' => [
               'analysis' => [
                    'filter' => [
                        'shingle' => [
                            'type' => 'shingle',
                            'min_shingle_size' => 2,
                            'max_shingle_size' => 3,
                        ],
                    ],
                    'analyzer' => [
                        'trigram' => [
                            'type' => 'custom',
                            'tokenizer' => 'standard',
                            'filter' => ['lowercase', 'shingle'],
                        ],
                    ],

            ],
            'mappings' => [
                'properties' => [
                    'title' => [
                        'type' => 'text',
                        'analyzer' => 'ngram_analyzer',
                        'fields' => [
                            'trigram' => [
                                'type' => 'text',
                                'analyzer' => 'trigram',
                            ],
                        ]
                    ],
                ]
            ]
        ]

```

The query looks like this:

```
'suggest' => [
                'simple_phrase' => [
                    'text' => $searchQuery,
                    'phrase' => [
                        'field' => 'title.trigram',
                        'confidence' => 0,
                        'collate' => [
                            'query' => [
                                'source' => [
                                    'match_phrase' => [
                                        'title' => '{{suggestion}}'
                                    ]
                                ]
                            ]
                        ],
                        'direct_generator' => [
                            [
                                'field' => 'title.trigram',
                                'suggest_mode' => 'always',
                            ],
                        ],
                        'highlight' => [
                            'pre_tag' => '<em>',
                            'post_tag' => '</em>',
                        ],
                    ],
                ],
            ],
        ]

```

What happens, is that I only get the suggestion text "ipad" and not the matched product title.

An example site is [https://bol.com](https://bol.com) and try searching for Ipad. I'm trying to achieve such a suggestion list.

Hopefully someone can help me find a solutions.

Kind regards!

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [May 10, 2021, 9:26am UTC](https://discuss.elastic.co/t/product-title-autocompletion-suggestions/271949/2 "2021-05-10T09:26:34Z")

</div>

As you mentioned the completion suggester is a pure prefix suggester. As an alternative you try the [search as you type field type](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/search-as-you-type.html).

---

<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: [June 7, 2021, 9:26am UTC](https://discuss.elastic.co/t/product-title-autocompletion-suggestions/271949/3 "2021-06-07T09:26:51Z")

</div>

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