elasticsearch-net icon indicating copy to clipboard operation
elasticsearch-net copied to clipboard

[FEATURE] ElasticSearch 8 took away support for "Nullable" fields for Term Query

Open DR9885 opened this issue 6 months ago • 9 comments

Is your feature request related to a problem? Please describe. ElasticSearch 8 took away support for "Nullable" fields for Term Query

Describe the solution you'd like Allow passing nullable values, if the value is null. Then the query is not generated.

Example: should not filter on "IsClosed"

        public async Task NullableExample(bool? isClosed)
        {
            var client = new ElasticsearchClient();
            var res = await client.SearchAsync<Account>(x => x.Index(AccountConstants.ViewId)
                .Query(q =>
                    q.Bool(b =>
                        b.Filter(
                            f => f.Term(m =>
                                m.Field(ff => ff.IsClosed)
                                    .Value(isClosed)
                            )
                        )
                    )
                ));
        }

Describe alternatives you've considered Adding an extension method to support this. But should be fixed in framework.

    public static class ElasticQueryExtensions
    {
        public static TermQueryDescriptor<TDocument> Value<TDocument>(this TermQueryDescriptor<TDocument> query, object value)
        {
            if (value != null) query.Value(value);
            return query;
        }
    }

DR9885 avatar Jan 04 '24 21:01 DR9885