'Combing a Terms Query and Numeric Range Query using Nest C#

I am are currently combining a TermQuery and a NumericRangeQuery against a nested object in a document.

Let's assume

{ "id": "329", "number": 150}

Then the Nest C# code

            var termQueries = requests
                                .Where(r => !string.IsNullOrWhiteSpace(r.Id))
                                .Select(r =>
                new TermQuery
                {
                    Field = "id",
                    Value = r.Id
                }
                &&
                new NumericRangeQuery
                {
                    Field = "number",
                    Boost = 1,
                    GreaterThanOrEqualTo = r.MinValue,
                    LessThanOrEqualTo = r.MaxValue
                }
            );

This works fine, but when a lot of requests are sent we end up hitting the indices.query.bool.max_clause_count so the sensible thing to try first is to optimize the query before upping the limit. A suggestion was to use a TermsQuery but I am not sure how to join this up with the NumericRangeQuery.

Does anyone have an idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source