I'm struggling with an elasticsearch nest query. I would like to display a list of WebPage documents. WebPage has a path, version, and isactive flag. There can be multiple WebPage documents with the same path, but only 0 or 1 documents for a path can have isactive = true. The result should be a list of all distinct paths and should use the document with isactive = true, but if there are no documents with isactive = true, then it should use the document with the highest version.
Here is my starting point with some other fields I am searching, but I am assuming this is all wrong and I will need to change this to add aggregations:
var filter = new List<Func<QueryContainerDescriptor<WebPage>, QueryContainer>>();
if (path != null)
{
filter.Add(fq => fq.Terms(t => t
.Field(f => f.path.Suffix("keyword")).Terms(path)
));
}
var should = new List<Func<QueryContainerDescriptor<WebPage>, QueryContainer>>();
if (search != null && search != string.Empty)
{
should.Add(fq => fq.Wildcard(c => c
.Field(f => f.pageTitle).Value(search.ToLower() + "*")
));
}
var response = await _elasticClient.SearchAsync<WebPage>(x => x
.Query(q => q
.Bool(bq => bq
.Filter(filter)
.Should(should)
)
)
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…