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

Percentiles(Kind=Keyed) order is not right #470

Closed
shi-yuan opened this issue Dec 25, 2022 · 2 comments
Closed

Percentiles(Kind=Keyed) order is not right #470

shi-yuan opened this issue Dec 25, 2022 · 2 comments

Comments

@shi-yuan
Copy link

Java API client version

8.5.3

Java version

17

Elasticsearch Version

8.5.3

Problem description

ElasticsearchClient elasticsearchClient = new ElasticsearchClient(getElasticsearchTransport(getRestClient()));
SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index("elasticsearch-sql_test_index_account");
builder.query(Query.of(q -> q.matchAll(MatchAllQuery.of(e -> e))));
builder.aggregations("percentiles(age)", Aggregation.of(a -> a.percentiles(PercentilesAggregation.of(
        e -> e.percents(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0).field("age")
))));
builder.size(0);
SearchRequest searchRequest = builder.build();
SearchResponse<Object> searchResponse = elasticsearchClient.search(searchRequest, Object.class);
System.out.println(searchResponse);

output:

SearchResponse: {
  "took": 4,
  "timed_out": false,
  "_shards": {
    "failed": 0,
    "successful": 1,
    "total": 1,
    "skipped": 0
  },
  "hits": {
    "total": {
      "relation": "eq",
      "value": 1000
    },
    "hits": [],
    "max_score": null
  },
  "aggregations": {
    "tdigest_percentiles#percentiles(age)": {
      "values": {
        "25.0": "25.0",
        "1.0": "20.0",
        "95.0": "39.0",
        "50.0": "31.0",
        "5.0": "21.0",
        "99.0": "40.0",
        "75.0": "35.0"
      }
    }
  }
}

but expected:

...
  "aggregations": {
    "tdigest_percentiles#percentiles(age)": {
      "values": {
        "1.0": "20.0",
        "5.0": "21.0",
        "25.0": "25.0",
        "50.0": "31.0",
        "75.0": "35.0",
        "95.0": "39.0",
        "99.0": "40.0"
      }
...

co.elastic.clients.elasticsearch._types.aggregations.Percentiles#buildPercentilesDeserializer use co.elastic.clients.json.JsonpDeserializerBase.StringMapDeserializer, but it's co.elastic.clients.json.JsonpDeserializerBase.StringMapDeserializer#deserialize method use HashMap,

I think, it should use LinkedHashMap to keep the order:
image

@sethmlarson
Copy link
Contributor

JSON object keys are unordered per the JSON standard, so I believe the implementation is correct as-is. Why do you need the ordering of keys here if you can access each known key individually?

@shi-yuan
Copy link
Author

I think, it is better to be consistent with the result of rest _search api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants