Using the Nest Client to Load Completion Fields in Elasticsearch

I would like to use Nest to populate the completion request field in the index. After reading this ElasticSearch post about implementing the completion field, I see that you can have the following properties:

  • array of inputs
  • single output
  • weight
  • Payload

I assume that in order to load this data into the index, do I need to include an object in my search object that contains the above fields?

+7
elasticsearch nest
source share
1 answer

I was able to finally load the completion field by creating several classes and following the FluentMappingFullExample unit test, specifically the next part

.Completion(s=>s .Name(p=>p.Name.Suffix("completion")) .IndexAnalyzer("standard") .SearchAnalyzer("standard") .MaxInputLength(20) .Payloads() .PreservePositionIncrements() .PreserveSeparators() ) 

For my search type object, I created a field called suggest and made it with type CompletionField.

  public class CompletionField { public CompletionField() { Input = new List<string>(); } public List<string> Input { get; set; } //public string Output { get; set; } public int Weight { get; set; } public Payload Payload { get; set; } } public class Payload { public int ID { get; set; } } 

After I loaded my entity from db using dapper, I then looped through the results and loaded my completion field with the corresponding entries that I wanted. Then I was able to successfully call the API request and the request for this data. Hope this helps someone else.

+8
source share

All Articles