我想使用nest及其对象初始值设定项语法在elasticsearch上构建一个动态查询。我想把一个表示位置id的整数列表传递给一个termsquery对象,我将用它来构建boolquery,这个boolquery将传递给searchrequest。termsquery对象接收一个没有任何问题的字符串列表,但是当涉及整数时,它返回一个强制转换问题。代码波纹管
//term locations DOESNT WORK
List<int> locationsTest = new List<int>();
locationsTest.Add(1);
locationsTest.Add(2);
locationsTest.Add(3);
TermsQuery locationstTerm = new TermsQuery()
{
Name = "Locations",
Boost = 1.1,
Field = "LocationId",
Terms = locationsTest
};
//terms Aggregation type WORKS FINE
List<string> types = new List<string> { "ParkedBy", "CheckedInBy", "RetrivedBy" };
TermsQuery aggregationsTerm = new TermsQuery()
{
Name = "AggregatorType_Query",
Boost = 1.1,
Field = "AggregatorType",
Terms = types
};
queryContainers.Add(aggregationsTerm);
BoolQuery boolQuery = new BoolQuery()
{
Filter=queryContainers
};
var searchRequest = new SearchRequest();
searchRequest.SearchType = SearchType.QueryThenFetch;
searchRequest.From = 0;
searchRequest.Size = DEFAULT_SCROLL_SIZE;
searchRequest.Query = boolQuery;
var searchResponse = Get().SearchAsync<List<AggregationHolder>>(new SearchRequest("0___aggregate"));
错误为“无法将类型“system.collections.generic.list”隐式转换为“system.collections.generic.ienumerable”。存在显式转换(是否缺少强制转换?)
1条答案
按热度按时间0mkxixxg1#
Terms
是一个IEnumerable<object>
所以你得把盒子装起来ints
自Int32
,与String
,是值类型:为什么我不能在.NET4.0中将list分配给ienumerable