Skip to content

[FEATURE] Make fluent creation of Terms query simpler #7716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stevejgordon opened this issue May 11, 2023 · 2 comments
Open

[FEATURE] Make fluent creation of Terms query simpler #7716

stevejgordon opened this issue May 11, 2023 · 2 comments
Labels

Comments

@stevejgordon
Copy link
Contributor

See this discuss issue for context. Due to the specification and code generation of types, constructing a terms query for a set of long values is more complex than we would like. We should look at improving this either with additional generated code or by adding manual code for conversions from common sets of FieldValues.

@stevejgordon stevejgordon added Feature 8.x Relates to a 8.x client version labels May 11, 2023
@stevejgordon stevejgordon changed the title Make fluent creation of Terms query simpler [FEATURE] Make fluent creation of Terms query simpler May 11, 2023
@DR9885
Copy link

DR9885 commented Jan 4, 2024

Having same issue. Using temporary workaround:

    public static class ElasticQueryExtensions
    {
        public static TermsQueryDescriptor<TDocument> Terms<TDocument>(this TermsQueryDescriptor<TDocument> query, long[] objs) => TermSelect(query, objs, FieldValue.Long);
        public static TermsQueryDescriptor<TDocument> Terms<TDocument>(this TermsQueryDescriptor<TDocument> query, double[] objs) => TermSelect(query, objs, FieldValue.Double);
        public static TermsQueryDescriptor<TDocument> Terms<TDocument>(this TermsQueryDescriptor<TDocument> query, string[] objs) => TermSelect(query, objs, FieldValue.String);
        public static TermsQueryDescriptor<TDocument> Terms<TDocument>(this TermsQueryDescriptor<TDocument> query, bool[] objs) => TermSelect(query, objs, FieldValue.Boolean);

        private static TermsQueryDescriptor<TDocument> TermSelect<TDocument, TValue>(TermsQueryDescriptor<TDocument> query, TValue[] objs, Func<TValue, FieldValue> selector)
        {
            var items = objs.Select(selector).ToArray();
            return query.Terms(new TermsQueryField(items));
        }
    }

Please fix soon.

@niemyjski
Copy link
Contributor

+1, this would be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants