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] Incorrect serialized aggregation response #1294

Closed
chanon-onman opened this issue Nov 14, 2024 · 1 comment
Closed

[BUG] Incorrect serialized aggregation response #1294

chanon-onman opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@chanon-onman
Copy link

What is the bug?

SearchResponse.toJsonString() generates incorrect aggregation response that doesn't match with what is in the documentation. The aggregation keys have extra prefix, e.g. lterms#, sterms#.

How can one reproduce the bug?

Execute the code below to get json serialized of search response.

SearchResponse resp = new SearchResponse.Builder<>()
        .aggregations("aggKey", v -> v.lterms(lv -> lv.buckets(b -> b.array(new ArrayList())).sumOtherDocCount(0)))
        .took(0)
        .timedOut(false)
        .shards(s ->s.failed(0).successful(1).total(1))
        .hits(h -> h.hits(new ArrayList()))
        .build();
System.out.println(resp.toJsonString());

The output is

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "failed": 0,
    "successful": 1,
    "total": 1
  },
  "hits": {
    "hits": []
  },
  "aggregations": {
    "lterms#aggKey": {    <--------*
      "buckets": [],
      "sum_other_doc_count": 0
    }
  }
}

What is the expected behavior?

Aggregation keys should not have other prefix according to the document: https://opensearch.org/docs/latest/aggregations/

What is your host/environment?

opensearch-java 2.17.0

@chanon-onman chanon-onman added bug Something isn't working untriaged labels Nov 14, 2024
@Xtansia Xtansia removed the untriaged label Nov 14, 2024
@Xtansia
Copy link
Collaborator

Xtansia commented Nov 14, 2024

This is not a bug but expected behavior, we (de)serialize aggregations following the behavior of the typed_keys parameter on the search api, this means aggregation keys are prefixed with their type so that there's no ambiguity in deserializing.

There is an existing issue #741 for adding a mechanism to disable the behavior.

@Xtansia Xtansia closed this as completed Nov 14, 2024
@Xtansia Xtansia closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants