How to do a suggest query in Low Level Client?


(Kartheek Gummaluri) #1

I have a suggest query I need to implement in c# Nest low level client.Can anyone help?


(Russ Cam) #2

You can send a JSON string, byte array or object using the low level client. If you use the low level client exposed on the high level client through the .LowLevel property, you can also take advantage of having a strongly typed SearchResponse<TDocument> response. for example, with a JSON string

var client = new ElasticClient();

var query = @"{
  ""suggest"": {
    ""my-completion-suggest"": {
      ""completion"": {
        ""analyzer"": ""simple"",
        ""contexts"": {
          ""color"": [
            {
              ""context"": ""red""
            }
          ]
        },
        ""field"": ""suggest"",
        ""fuzzy"": {
          ""fuzziness"": ""AUTO"",
          ""min_length"": 1,
          ""prefix_length"": 2,
          ""transpositions"": true,
          ""unicode_aware"": false
        },
        ""size"": 8
      },
      ""prefix"": ""Durgan LLC""
    }
  }
}";

var response = 
    client.LowLevel.Search<SearchResponse<YourDocument>>("index", "type",  query);

Take a look at Suggester usage for examples with the high level client


(system) #3

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