Hi Vineeth,

I'm afraid that this won't work, because as I said "element" can have high 
cardinality (while it's not bounded in theory, in practice it will range 
from 500 to 40000). Therefore if I do a "terms" on element, then a top hit, 
it will require to generate maybe 40000 sub-buckets. I think this will kill 
performance.

For now, I've rethought my format so it now looks like this:

{
   "element": "abc",
   "history": [
      {"type": "A", "date": "2014-01-01"},
      {"type": "B", "date": "2014-01-02"}
   ]
}

Where history is mapped as nested. Now, I can do that:

{
  "aggs": {
    "history": {
      "nested": {
        "path": "history"
      },
      "aggs": {
        "latest-history": {
          "filter": {
            "limit": {
              "value": 1
            }
          },
          
          "aggs": {
            "by-type": {
              "terms": {
                "field": "history.type",
                "size": 0
              }
            }
          }
        }
      }
    }
  }
}

This will get the nested history, limit by 1, then group by type, so I can 
get the count of the ones I'm interested (A type or B type). The only 
drawback is that inside the history nested, I need to sort the history by 
date in my application (I have not found any way to sort the nested by date 
before doing the limit filter...), and that while history is typically 
quite low (around 10-200 elements), it is not bounded, and updating is 
harder to do...

If anyone has any other idea, don't hesitate to share!


-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/3948211d-2029-42f4-a07a-3ff0ba1834c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to