public List <string> Suggest(string index, string text) { List <string> suggestions = new List <string>(); List <string> fieldsToWorkOn = new List <string>(); List <string> suggestionNames = new List <string>(); Type t = typeof(T); foreach (var m in t.GetProperties()) { if (m.GetCustomAttributes(typeof(TermSuggest), true).Length > 0) { fieldsToWorkOn.Add(m.Name); } } JObject query = new JObject(); JProperty propTextToSuggest = new JProperty("text", text); query.Add(propTextToSuggest); foreach (string fieldName in fieldsToWorkOn) { JObject termObject = new JObject(); JProperty field = new JProperty("field", fieldName); termObject.Add(field); JObject suggest = new JObject(); suggest.Add("term", termObject); string suggestName = $"my-suggestion-{Guid.NewGuid().ToString()}"; suggestionNames.Add(suggestName); query.Add(suggestName, suggest); } string json = JsonConvert.SerializeObject(query); PostData <object> jsonPostData = new PostData <object>(json); ElasticsearchResponse <object> results = _elasticsearchClient.Suggest <object>(index, jsonPostData); JObject result = JObject.Parse(results.Body.ToString()); foreach (string suggestionName in suggestionNames) { MySuggestion[] suggestion = JsonConvert.DeserializeObject <MySuggestion[]>(result[suggestionName].ToString()); List <KeyValuePair <string, List <string> > > options = suggestion.Select(x => new KeyValuePair <string, List <string> >(x.text, x.options.Select(y => y.text).ToList())).ToList(); if (options.Sum(x => x.Value.Count()) > 0) // there is options to suggest { suggestions.AddRange(GetCombos(options)); } } return(suggestions.Distinct().ToList()); }