我想使用SearchRequest对象对几种类型进行请求
我的请求看起来像下面的代码:
var searchQuery = new BoolQuery
{
Should = shouldContainers,
Filter = filterContainers
};
var searchRequest = new SearchRequest<dynamic>()
{
//Don't know how to target type
Type = EType.All,
//or
Type = typeof(obj1) && typeof(obj2)
Query = searchQuery,
Size = size
From = fromNumber,
MinScore = 1
};
var response = await client.SearchAsync<dynamic>(searchRequest);
你知道是否有可能做这样的事情以及如何做到这一点?
答案 0 :(得分:1)
如果未在端点中指定索引/类型,它将搜索整个群集。
更新
//
// Summary:
// /_search
//
// Parameters:
// document:
// describes an elasticsearch document of type T, allows implicit conversion from
// numeric and string ids
public SearchRequest();
//
// Summary:
// /{index}/_search
//
// Parameters:
// index:
// Optional, accepts null
public SearchRequest(Indices index);
//
// Summary:
// /{index}/{type}/_search
//
// Parameters:
// index:
// Optional, accepts null
//
// type:
// Optional, accepts null
public SearchRequest(Indices index, Types type);
// The second one is what you are looking for, query on specific index regardless type, it does `POST /{index}/_search`
var searchRequest = new SearchRequest(myIndex){...}
var result = client.Search<dynamic>(searchRequest);