0

I have added the following snippet in a nest query which returns a ISearchResponse<T>

.Query(query => query.Match(m =>
    m.Field(f =>
        f => !string.IsNullOrEmpty(f.Purchase.NationalCode.Trim()))
    )))

But it makes no difference to the amount of records returned (and I know there are nulls in there)

Should I do be building my query some other way?

Edited to add: I've tried the following based on this answer here but no luck either

.Query(query => query.Bool(b=>
   b.Must(m=> m.Exists(
      f=>f.Field("nationalCode")))))
.Query(query => query.Bool(b=>
   b.MustNot(m=> m.Term(
      "nationalCode", ""))))
atamata
  • 997
  • 3
  • 14
  • 32

1 Answers1

0

Try the following

.Query(query => query
    .Bool(b => b
        .Must(m => m
            .Exists(f => f.Field("nationalCode"))
        )
        .MustNot(m => m
            .Term("nationalCode", "")
        )
    )
)

Both the .Must and .MustNot need to be called on the same bool query descriptor

Russ Cam
  • 124,184
  • 33
  • 204
  • 266