从NEST中的索引名称推断弹性搜索类型

时间:2020-03-24 07:47:18

标签: elasticsearch nest

由于我要调用多个索引并且必须使用object类型,因此可以通过索引名称来推断弹性搜索文档的类型。

        var indices = Indices.Index(entities);

        var search = new SearchRequest(indices)
        {
            From = page,
            Size = pageSize,
            Query = fullQuery,
            IgnoreUnavailable = true,
        };

        var response = this.client.Search<object>(search);

是否可以基于某种type / indexName映射从弹性搜索中推断出每个对象的类型?

1 个答案:

答案 0 :(得分:0)

也许您可以尝试泛型。

var indices = Indices.Index(entities);

var search = new SearchRequest(indices)
{
    From = page,
    Size = pageSize,
    Query = fullQuery,
    IgnoreUnavailable = true,
};

var response = this.client.Search<T>(search);
return response;