Search code examples
c#elasticsearchnest

ElasticSearch Nest - query on an array field


I have document that contains an array element:

{
...,
"roles": ["Worker", "Admin",...]
...
}

How can I create a query that returns all documents where on this array all values are NOT "client" for example?


Solution

  • Must not query in nest

    var searchResults = this.elasticClient.Search<Model>(s => s
        .Query(q => q
            .Bool(b => b
                .MustNot(
                    bs => bs.Term(p => p.roles, "client"),
                )
            )
        )
    );