arranblue
arranblue

Reputation: 197

How do I create a CompletionField with multiple inputs that have different weights?

For a single Input suggestion list the following code works:

     var completionField = new CompletionField

     {
         Input = completionList,
         Weight = weight

     };

     this.Suggest = completionField;

But I would like to have multiple lists of suggestions with different weights and be able to search a single completion field. I'm not sure how to accomplish that in Nest.

I do see that it is supported though:

PUT music/song/1?refresh
{
    "suggest" : [
        {
            "input": "Nevermind",
            "weight" : 10
        },
        {
            "input": "Nirvana",
            "weight" : 3
        }
    ]
}

Upvotes: 1

Views: 275

Answers (1)

Graeme
Graeme

Reputation: 26

If you define your completion field like this:

[Completion]
public List<CompletionField> Suggest { get; set; }

And provide a list of completion fields (with different weights if desired) you'll end up with the following in your index.

"suggest": [
  {
    "input": [
      "higherweightedterm"
    ],
    "weight": 1000
  },
  {
    "input": [
      "lowerweightedterm"
    ],
    "weight": 100
  }
]

Upvotes: 1

Related Questions