Skip to content
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

Aggregations Filters :The JSON value could not be converted to System.Collections.Generic.IReadOnlyCollection`1[Elastic.Clients.Elasticsearch.Aggregations.FiltersBucket]. Path: $.buckets | #8040

Closed
mike48785601 opened this issue Feb 16, 2024 · 1 comment
Labels
8.x Relates to 8.x client version Area: Generator Category: Bug

Comments

@mike48785601
Copy link

mike48785601 commented Feb 16, 2024

Elastic.Clients.Elasticsearch version:8.9.0

Elasticsearch version:8.12.0

.NET runtime version:net6.0

Operating system version:Windows 10 professional edition

Description of the problem including expected versus actual behavior:
Error is happend,and how to fix it.

Steps to reproduce:

public class buy
{
    [JsonPropertyName("Id")]
    /// <summary>
    /// 供求信息编号
    /// </summary>
    public int BuyId { set; get; }
    /// <summary>
    /// 用户编号
    /// </summary>
    /// 
    [JsonPropertyName("Userid")]
    public int Userid { set; get; }
    /// <summary>
    /// 标题
    /// </summary>
    /// 
    [JsonPropertyName("Title")]
    public string Title { set; get; }

    [JsonPropertyName("Ischengxin")]
    public int Ischengxin { set; get; }
}

var settings = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
.CertificateFingerprint("9d71addba27bb5efa9e8c45f529f3c9980314106acf62d46672c212c8053e2ee")//8.12 local
.Authentication(new BasicAuthentication("elastic", "xmdC3QQJmkZT5u=AdeOt"))//8.12 local
.DefaultMappingFor(i => i
.IndexName("buyindex")
.IdProperty(s => s.BuyId))
.EnableDebugMode();
var client = new ElasticsearchClient(settings);

        TermQuery aaa = new TermQuery("Ischengxin");
        aaa.Value = 1;
        Query qq = Query.Term(aaa);
        var bkt = new Buckets<Query>(new Dictionary<string, Query>
        {
            { "chengxin_filter",qq }
        }
        );

        var qr1 = client.Search<buy>(s => s
                       .Query(q => q
                       .MatchAll()
                       )
                       .Aggregations(a => a
    
                                       .Filters("f", c => c
                                                    .Filters(bkt)
                                                    .Aggregations(t => t
                                                            .Terms("Userid", ss => ss.Field(f => f.Userid).Aggregations(cc => cc.Max("maxBuyid", avg => avg.Field(p => p.BuyId))))

                                                   )

                                           )
                                   )
                       .Size(3)
                       .From(0)
                       );

Expected behavior
{
"aggregations": {
"f": {
"filters": {
"filters": {
"chengxin_filter": {
"term": {
"Ischengxin": {
"value": 1
}
}
}
}
},
"aggregations": {
"Userid": {
"terms": {
"field": "Userid"
},
"aggregations": {
"maxBuyid": {
"max": {
"field": "Id"
}
}
}
}
}
}
},
"query": {
"match_all": {}
}
}

Provide DebugInformation (if relevant):
Elastic.Transport.UnexpectedTransportException
HResult=0x80131500
Message=The JSON value could not be converted to System.Collections.Generic.IReadOnlyCollection1[Elastic.Clients.Elasticsearch.Aggregations.FiltersBucket]. Path: $.buckets | LineNumber: 1 | BytePositionInLine: 19. Source=Elastic.Transport StackTrace: 在 Elastic.Transport.DefaultHttpTransport1.ThrowUnexpectedTransportException[TResponse](Exception killerException, List1 seenExceptions, RequestData requestData, TResponse response, RequestPipeline pipeline) 在 Elastic.Transport.DefaultHttpTransport1.Request[TResponse](HttpMethod method, String path, PostData data, RequestParameters requestParameters)
在 Elastic.Clients.Elasticsearch.ElasticsearchClient.DoRequest[TRequest,TResponse,TRequestParameters](TRequest request, Action`1 forceConfiguration)
在 es882.Form1.btnbuy_Click(Object sender, EventArgs e) 在 C:\Users\Administrator\source\estest\es882\Form1.cs 中: 第 763 行
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

此异常最初是在此调用堆栈中引发的:
System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(System.Type)
System.Text.Json.Serialization.JsonCollectionConverter<TCollection, TElement>.OnTryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out TCollection)
System.Text.Json.Serialization.JsonConverter.TryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out T)
System.Text.Json.Serialization.Metadata.JsonPropertyInfo.ReadJsonAndSetMember(object, ref System.Text.Json.ReadStack, ref System.Text.Json.Utf8JsonReader)
System.Text.Json.Serialization.Converters.ObjectDefaultConverter.OnTryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out T)
System.Text.Json.Serialization.JsonConverter.TryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out T)
System.Text.Json.Serialization.JsonConverter.ReadCore(ref System.Text.Json.Utf8JsonReader, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack)
System.Text.Json.JsonSerializer.ReadCore(System.Text.Json.Serialization.JsonConverter, ref System.Text.Json.Utf8JsonReader, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack)
System.Text.Json.JsonSerializer.Read(ref System.Text.Json.Utf8JsonReader, System.Text.Json.Serialization.Metadata.JsonTypeInfo)
Elastic.Clients.Elasticsearch.Aggregations.AggregateDictionaryConverter.ReadAggregate(ref System.Text.Json.Utf8JsonReader, System.Text.Json.JsonSerializerOptions, System.Collections.Generic.Dictionary<string, Elastic.Clients.Elasticsearch.Aggregations.IAggregate>, string)
...
[调用堆栈已截断]

内部异常 1:
JsonException: The JSON value could not be converted to System.Collections.Generic.IReadOnlyCollection`1[Elastic.Clients.Elasticsearch.Aggregations.FiltersBucket]. Path: $.buckets | LineNumber: 1 | BytePositionInLine: 19.

@mike48785601 mike48785601 added the 8.x Relates to 8.x client version label Feb 16, 2024
@flobernd flobernd added the bug label Feb 19, 2024
@flobernd flobernd added Category: Bug and removed bug labels Apr 4, 2024
@flobernd
Copy link
Member

This is fixed in 8.13.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Area: Generator Category: Bug
Projects
None yet
Development

No branches or pull requests

2 participants