# AutoComplete Posted Tags

**URL:** <https://discuss.elastic.co/t/autocomplete-posted-tags/156518>\
**Category:** Elasticsearch\
**Created:** [November 13, 2018, 5:20pm UTC](https://discuss.elastic.co/t/autocomplete-posted-tags/156518 "2018-11-13T17:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavankrishna116](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pavankrishna116/32/37498_2.png) [@pavankrishna116](https://discuss.elastic.co/u/pavankrishna116)\
**Post date:** [November 13, 2018, 5:20pm UTC](https://discuss.elastic.co/t/autocomplete-posted-tags/156518/1 "2018-11-13T17:20:06Z")

</div>

I have an Object in that I have a field Name _Tags_ of type string.

Ex: "Dubai,India, Australia"

I implemeted AutoComplete for this, if I try to search Dubai i.e; Dub will Dubai be shown as a autocomplete tag or the complete "Dubai,India, Australia" will be shown.

```
public async Task<List<Tag>> Autocomplete(string query)
        {
            var response = await this.client.SearchAsync<BlogPost>(sr => sr
                .Suggest(scd => scd
                    .Completion("tag-completion", cs => cs
                        .Prefix(query)
                        .Fuzzy(fsd => fsd
                            .Fuzziness(Fuzziness.Auto))
                        .Field(r => r.Tags))));

            List<Tag> tagSuggestions = ExtractAutocompleteSuggestions(response);
            return tagSuggestions;

        }

 private List<Tag> ExtractAutocompleteSuggestions(ISearchResponse<BlogPost> response)
        {
            List<Tag> results = new List<Tag>();
            var suggestions = response.Suggest["tag-completion"].Select(s => s.Options);
            suggestions.ToList().ForEach(s =>
            {
                results.AddRange(s.Select(opt => new Tag
                {
                    Tags = opt.Source.Tags
                }));
            });
            return results;
        }

```

This is the code that I Implemented for the Model brlow.  
public class BlogPost  
{  
public string BlogId { get; set; }  
public string Content { get; set; }  
[Completion]  
public string Tags { get; set; }  
public DateTime PostedDate { get; set; }  
public string Category { get; set; }  
[Text]  
public string Title { get; set; }  
}

---

<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:** [December 11, 2018, 5:20pm UTC](https://discuss.elastic.co/t/autocomplete-posted-tags/156518/2 "2018-12-11T17:20:07Z")

</div>

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