0
votes

Following http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html

How can I index/insert (I can do mapping) an object using Nest client library to be able to provide following options:

"input": ...,
"output": ...,
"payload" : ...,
"weight" : ...

I would like to be able to provide multiple values in 'input' option. Can't find anyway of doing this using NEST.

Thank you

1

1 Answers

4
votes

NEST provides the SuggestField type in order to assist in indexing completion suggestions. You don't necessarily need to use this type, you can provide your own that contains the expected completion fields (input, output, etc...), but the purpose of SuggestField is to make the whole process easier by already providing a baked in type.

Usage:

Add a suggest field to the document/type you are indexing:

public class MyType
{
    public SuggestField Suggest { get; set; }
}

Your mapping should look something like:

client.Map<MyType>(m => m
    .Properties(ps => ps
        .Completion(c => c.Name(x => x.Suggest).Payloads(true))
    )
);

Indexing example:

var myType = new MyType
{
    Suggest = new SuggestField
    {
        Input = new [] { "Nevermind", "Nirvana" },
        Output = "Nirvana - Nevermind",
        Payload = new { id = 1234 },
        Weight = 34
    }
};

client.Index<MyType>(myType);

Hope that helps.