elasticsearch-net
elasticsearch-net copied to clipboard
[FEATURE] ElasticSearch 8 took away support for "Nullable" fields for Term Query
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;
}
}