-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bug in TermsQueryDescriptor when passing to Terms IEnumerable<TValue> #1930
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
Comments
I am also experiencing this using Elasticsearch 2.2.| |
@alekole, Thanks for reporting. The public class TermsQueryDescriptor<T>
: FieldNameQueryDescriptorBase<TermsQueryDescriptor<T>, ITermsQuery, T>
, ITermsQuery where T : class
{
protected override bool Conditionless => TermsQuery.IsConditionless(this);
MinimumShouldMatch ITermsQuery.MinimumShouldMatch { get; set; }
bool? ITermsQuery.DisableCoord { get; set; }
IEnumerable<object> ITermsQuery.Terms { get; set; }
IFieldLookup ITermsQuery.TermsLookup { get; set; }
public TermsQueryDescriptor<T> TermsLookup<TOther>(Func<FieldLookupDescriptor<TOther>, IFieldLookup> selector)
where TOther : class => Assign(a => a.TermsLookup = selector(new FieldLookupDescriptor<TOther>()));
public TermsQueryDescriptor<T> MinimumShouldMatch(MinimumShouldMatch minMatch) => Assign(a => a.MinimumShouldMatch = minMatch);
public TermsQueryDescriptor<T> DisableCoord(bool? disable = true) => Assign(a => a.DisableCoord = disable);
public TermsQueryDescriptor<T> Terms<TValue>(IEnumerable<TValue> terms) => Assign(a => a.Terms = terms?.Cast<object>());
public TermsQueryDescriptor<T> Terms<TValue>(params TValue[] terms) => Assign(a => a.Terms = terms?.Cast<object>());
} The problem that you are experiencing here is that the compiler is preferring the var descr = new QueryContainerDescriptor<SearchProductCard>().Terms(t => t
.Field("field")
// specify generic parameter type to be int
.Terms<int>(new List<int> {1,2})
); The |
When calling ```csharp .Terms(new List<T>()); ``` The user expects T[] to be written to elasticsearch but due to C# resolution they end up calling ```csharp .Terms<List<T>>(params List<T>) ``` and we serialize to T[][] which is not a valid terms query. The fluent Terms() method now tries to preempt these cases and unwraps to T[] when a single IEnumerable is passed as T, special casing `string` to be exluded from the unwrapping behavior so we do not unwrap string to char[]
When calling ```csharp .Terms(new List<T>()); ``` The user expects T[] to be written to elasticsearch but due to C# resolution they end up calling ```csharp .Terms<List<T>>(params List<T>) ``` and we serialize to T[][] which is not a valid terms query. The fluent Terms() method now tries to preempt these cases and unwraps to T[] when a single IEnumerable is passed as T, special casing `string` to be exluded from the unwrapping behavior so we do not unwrap string to char[]
if i have some descriptor like
var descr = new QueryContainerDescriptor<SearchProductCard>().Terms(t => t.Field("field").Terms(new List<int> {1,2}));
it will transfer in
This causes an error in elastic
I have noticed that before commit e1e467e2 there was an explicit conversion to array
and missed later
The text was updated successfully, but these errors were encountered: