Or Assayag
Or Assayag

Reputation: 6336

Elasticsearch - Term null?

I'm having trouble matching null terms in NEST. I'm trying to get some details via a query. It works ok, but one thing I can't understand - For some reason I can't do a term that equals to null value. What am I doing wrong?

My Code:

                result = _mainManager.Client.Search<object>
            (q => q
             .Type("Mail")
             .Query(c =>
                    c.Term("SentMail_Sender_Id", userId) &&
                    c.Term("SentMail_EmbedAccountId", null) &&
                    !c.Term("SentMail_Status", Status.REMOVED.ToString().ToLower()) &&
                    c.Range(v => v.OnField("SentMail_Upload_Files_Count").Greater(0)))
             .Size(int.MaxValue)
             .Sort(s => s.OnField("SentMail_Creation_Date").Descending()));

It works ok, no null term is found in my result Json:

 {
 "size": 2147483647,
 "sort": [
 {
   "SentMail_Creation_Date": {
    "order": "desc"
    }
  }
],
"query": {
"bool": {
   "must": [
     {
      "term": {
        "SentMail_Sender_Id": {
          "value": 7186
        }
      }
    },
    {
      "range": {
        "SentMail_Upload_Files_Count": {
          "gt": "0"
        }
      }
    }
  ],
  "must_not": [
    {
       "term": {
         "SentMail_Status": {
           "value": "removed"
        }
      }
    }
   ]
  }
 }
}

Upvotes: 1

Views: 558

Answers (1)

Or Assayag
Or Assayag

Reputation: 6336

Found it!

                result = _mainManager.Client.Search<object>
            (q => q
             .Type("Mail")
             .Query(c =>
                    c.Term("SentMail_Sender_Id", userId) &&
                    !c.Term("SentMail_Status", Status.REMOVED.ToString().ToLower()) &&
                    c.Range(v => v.OnField("SentMail_Upload_Files_Count").Greater(0)))
            .Filter(f => f.Missing("SentMail_EmbedAccountId"))
            .Size(int.MaxValue)
            .Sort(s => s.OnField("SentMail_Creation_Date").Descending()));

Upvotes: 1

Related Questions