Elasticsearch 嵌套初始化的 TermsQuery 对象不允许整数列表

Elasticsearch nest initialized TermsQuery object doesn't allow a list of integers

我想使用 nest 及其对象初始化语法在 Elasticsearch 上构建动态查询。我想将表示位置 ID 的整数列表传递给 TermsQuery 对象,我将使用它来构建将传递给 SearchRequest 的 BoolQuery。 TermsQUery 对象接收到一个字符串列表,没有任何问题,但是 returns 当涉及到整数时,它是一个转换问题。代码如下

        //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'。存在显式转换(是否缺少强制转换?) “

Terms 是一个 IEnumerable<object>,因此您需要将 ints 框起来,因为 Int32String 不同,它是一个值类型:

TermsQuery locationstTerm = new TermsQuery()
{
    Name = "Locations",
    Boost = 1.1,
    Field = "LocationId",
    Terms = locationsTest.Select(x => (object)x).ToArray()
};

Why can't I assign List<int> to IEnumerable<object> in .NET 4.0