Giter Site home page Giter Site logo

Comments (9)

olivere avatar olivere commented on August 15, 2024

Can you send me your query and the results? Set Pretty(true).Debug(true) in the SearchService and paste the output (like here)?

from elastic.

kylebrandt avatar kylebrandt commented on August 15, 2024

Query:

{"aggregations":{"g_TargetUserName":{"aggregations":{"g_eventlog_id":{"aggregations":{"ts":{"date_histogram":{"field":"@timestamp","interval":"1m"}}},"terms":{"field":"TargetUserName"}}},"terms":{"field":"eventlog_id"}}},"query":{"range":{"@timestamp":{"from":"2015-01-08T15:54:50.750119001Z","include_lower":true,"include_upper":true,"to":"2015-01-08T16:04:50.750119001Z"}}}}

(Also side bug, Query output in debug doesn't pretty format (although I care more about having access to the rawquery in code anyways).

Head of Response, note the Keys are Ints of some sort (not quoted).

  "aggregations" : {
    "g_TargetUserName" : {
      "doc_count_error_upper_bound" : 2,
      "sum_other_doc_count" : 2487,
      "buckets" : [ {
        "key" : 5447,
        "doc_count" : 2448,
        "g_eventlog_id" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [ ]
        }
      }, {
        "key" : 16,
        "doc_count" : 984,
        "g_eventlog_id" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [ ]
        }
      }, {
        "key" : 4624,
        "doc_count" : 829,
        "g_eventlog_id" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 141,
          "buckets" : [ {
            "key" : "system",
            "doc_count" : 194,
            "ts" : {
              "buckets" : [ {
                "key_as_string" : "2015-01-08T15:54:00.000Z",

from elastic.

olivere avatar olivere commented on August 15, 2024

Can you update and try again? Should be fixed with this commit. Reopen if necessary.

from elastic.

kylebrandt avatar kylebrandt commented on August 15, 2024

I don't think this is going to be correct, since the key can be a number or a string (possibly other things)...

from elastic.

olivere avatar olivere commented on August 15, 2024

And in the tests, the key is indeed a string for e.g. the "users" aggregation.

from elastic.

kylebrandt avatar kylebrandt commented on August 15, 2024

So probably an interface, and then the user has to type switch I imagine? I had another idea but can't remember now...

from elastic.

olivere avatar olivere commented on August 15, 2024

We could to that as well. And you're right in that it's better because Keys can be of any type, not only strings and numbers.

However, remember that you'll then get a float64 when decoding the "Key" in your example. A type switch is not enough.

from elastic.

olivere avatar olivere commented on August 15, 2024

Maybe we could have the best of both worlds with this.

type AggregationBucketKeyItem struct {
    Aggregations

    Key       interface{}
    KeyNumber json.Number
    DocCount  int64
}

You could use Key to get to the interface{} while still having KeyNumber for convenience.

if bucket.Key != float64(0) {
    t.Errorf("expected %v; got: %v", float64(0), bucket.Key)
}
if got, err := bucket.KeyNumber.Int64(); err != nil {
    t.Errorf("expected %d; got: %v", 0, bucket.Key)
} else if got != 0 {
    t.Errorf("expected %d; got: %d", 0, got)
}
if bucket.KeyNumber != "0" {
    t.Errorf("expected %q; got: %q", "0", bucket.KeyNumber)
}

from elastic.

olivere avatar olivere commented on August 15, 2024

See this test for example usage.

Hope this is going to fix it.

Thanks for reporting.

from elastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.