我正在努力实现类似的目标
.Where(m => m.PublishedDate.Value < m.LastUpdatedDate)
在弹性搜索中。这里PublishedDate
是可以为null的。
到目前为止,我已经尝试了以下方法,但似乎不起作用。
var res2 = client.Search<Campaign>(c => c
.Source(s => s.Includes(i => i
.Field(f => f.CampaignId)
.Field(f => f.Offers.First().DateLastUpdated)
.Field(f => f.Offers.First().DateLastPublished)))
.Query(q => q
.Bool(b => b
.Must(m => m.Exists(t => t.Field(f => f.Offers.First().DateLastPublished)))
.Must(m => m.Term(t => t.Offers.First().DateLastPublished.Value < t.Offers.First().DateLastUpdated, true))
.Should(s =>
s.Term(t => t.Offers.First().Approved, true), s =>
s.Term(t => t.Offers.First().Deleted, true))
.MinimumShouldMatch(new MinimumShouldMatch(1))))
.Size(1000)
);
有人能帮忙吗?感谢
我能够通过以下方式实现它。
var res3 = client.Search<Campaign>(c => c
.Source(s => s.Includes(i => i
.Field(f => f.CampaignId)))
.Query(q => q.ConstantScore(cs => cs.Filter(fs => fs
.Bool(b => b
.Must(m =>
m.Exists(e => e.Field(f => f.Offers.First().DateLastPublished)), m =>
m.Exists(e => e.Field(f => f.Offers.First().DateLastUpdated)), m =>
m.Script(s => s.Script(ss => ss
.Source("doc['offers.dateLastPublished'].value.getMillis() < doc['offers.dateLastUpdated'].value.getMillis()"))))
.Should(s =>
s.Term(t => t.Offers.First().Approved, true), s =>
s.Term(t => t.Offers.First().Deleted, true))
.MinimumShouldMatch(new MinimumShouldMatch(1))))))
.Size(1000))