Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
877 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...