📜  elasticsearch 模拟聚合字典存储桶响应示例 - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:42.955000             🧑  作者: Mango

代码示例1
var client = new Mock();

var searchResponse = new Mock>();

var aggregations = new AggregateDictionary(new Dictionary {
    ["Name"] = new BucketAggregate
    {
        Items = new List>
        {
            new Nest.KeyedBucket(new Dictionary())
            {
                Key = "XYZ school",
                KeyAsString = null,
                DocCount = 5
            }
        }.AsReadOnly()
    }
});

searchResponse.Setup(s => s.Aggregations).Returns(aggregations);

client.Setup(c => c.Search(It.IsAny, ISearchRequest>>()))
    .Returns(searchResponse.Object);

var response = client.Object.Search(s => s);

var terms = response.Aggregations.Terms("Name");