Elasticsearch - 术语null?

时间:2015-06-19 16:56:14

标签: elasticsearch nest

我很难在NEST中匹配null term。 我试图通过查询获取一些细节。 它运作正常,但有一点我无法理解 - 出于某种原因,我不能使用等于null值的术语。 我做错了什么?

我的代码:

                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()));

它工作正常,我的结果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"
        }
      }
    }
   ]
  }
 }
}

1 个答案:

答案 0 :(得分:1)

发现它!

                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()));