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

[BUG] Cannot output AggregateDictionary as JSON #318

Open
winzig opened this issue Aug 16, 2023 · 1 comment
Open

[BUG] Cannot output AggregateDictionary as JSON #318

winzig opened this issue Aug 16, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@winzig
Copy link

winzig commented Aug 16, 2023

What is the bug?

I'm trying to output an AggregateDictionary to the end-user browser as JSON. When I do this, all of the properties of the object seem to be at their default state (nulls, 0s, Items are just empty JSON objects instead of IBuckets, etc).

How can one reproduce the bug?

I'm doing a simple Terms based aggregate request in my query:

new AggregationDictionary()
{
    ["DiscussionTypes"] = new AggregationContainer
    {
        Terms = new TermsAggregation("CommunityTypeId")
        {
            Field = "CommunityTypeId",
            Size = 1000
        }
    }
}

The JSON coming back from OpenSearch makes sense to me:

"aggregations": {
    "DiscussionTypes": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 4,
          "doc_count": 364
        },
        {
          "key": 3,
          "doc_count": 88
        },
        {
          "key": 1,
          "doc_count": 28
        },
        {
          "key": 6,
          "doc_count": 13
        },
        {
          "key": 7,
          "doc_count": 13
        },
        {
          "key": 8,
          "doc_count": 12
        },
        {
          "key": 12,
          "doc_count": 12
        },
        {
          "key": 2,
          "doc_count": 6
        },
        {
          "key": 13,
          "doc_count": 3
        },
        {
          "key": 9,
          "doc_count": 2
        },
        {
          "key": 5,
          "doc_count": 1
        }
      ]
    }
  }

Then I return the Aggregations property from the ISearchResponse that I get back from the OpenSearch client to the client, something I do with C# objects all the time in my web app, and it comes out looking like this below. Notice that there are 11 empty Items objects, matching the 11 results in the JSON data above.

"DiscussionTypes": {
    "AfterKey": null,
    "BgCount": 0,
    "DocCount": 0,
    "DocCountErrorUpperBound": 0,
    "Items": [
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {}
    ],
    "Meta": null,
    "SumOtherDocCount": 0,
    "AutoInterval": null
}

Typically when I see behavior like this in my own code, it's because I've over-zealously put a [JsonIgnore] on a property, or have the property defined with a private set. Is that possibly the problem here within the OS code base?

What is the expected behavior?

Outputting an AggregateDictionary should export all of the public fields via JSON.

What is your host/environment?

OpenSearch.Client 1.4.0 connected to OpenSearch 2.7 running in AWS OpenSearch Service (also tried it with Client 1.3.0 and OpenSearch 2.5).

@winzig winzig added bug Something isn't working untriaged labels Aug 16, 2023
@Xtansia Xtansia removed the untriaged label Aug 18, 2023
@Xtansia
Copy link
Collaborator

Xtansia commented Aug 18, 2023

Hi @winzig, this is not exactly a bug as the types within the client are not written with the intention or expectation of being (de)serializable outside of the client. This would not be feasible to implement or maintain due to the extent of the client and differing behaviours between the various potential JSON implementations (Newtonsoft, System.Text, Utf8Json, etc).

I think it would be useful if you could provide a bit more information about your usecase. There are mechanisms to get the raw json response or a dynamic object with the low-level client if you're not planning on doing much manipulation in C#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants