2016-01-20 61 views
0

因此docs总是使用任意日期作为检查的值。ElasticSearch范围基于其他字段的查询

,如果我有这对这些属性的对象:

DateTime DueDate 
DateTime NotRequired 

我怎么做这样的事情:

{ 
    "range" : { 
     "NotRequired" : { 
      "gt" : "DueDate" 
     } 
    } 
} 

因此有效地让你得到了我的所有实体,其中NotRequired > DueDate的简单查询?

回答

3

range查询只接受特定的值。但是你可以使用script filter来达到你想要的效果,它可以比较两个日期。

"bool" : { 
    "filter" : { 
     "script" : { 
      "script" : "doc.NotRequired.date > doc.DueDate.date" 
     } 
    } 
} 

请注意,为了这个工作,你需要enable dynamic scripting