Search code examples
nest

Nest ElasticSearch cannot convert Lambda expression


The following VB code is intended to add an alias index to a nest elastic search but the final line receives an error -

"lambda expression cannot be converted to NEST.IAliasRequest because Nest.IAliasRequest is not a delegate type"

    Dim client = ConnectToSearch()

    Dim Person = New Person With {.Id=  Id, .Description = Description, .Tags = Tags}

    client.Alias(Sub(a) a.Add(Function(add) add.Index("Person").Alias("Account1")))

Solution

  • client.[Alias](Function(descriptor) descriptor.Add(Function(a) a.Index("Person").[Alias]("Account1")))
    

    UPDATE

    Maybe this one will help you create alias with filter.

    client.[Alias](Function([alias]) [alias].Add(Function(a) a.Index(indexName).[Alias]("alias").Filter(Of Person)(Function(f) f.Term("relationships.staffID", staffID))))
    

    Hope this helps.