Return multiple 1-1 fields with aggregation


(Andrew B) #1

I'm somewhat new to elastic search, so my apologies if any part of this doesn't make sense :slight_smile:

I'm in need of the ability to get multiple one-to-one fields back from an aggregation. I understand the obvious reason why one would only be able to aggregate on a single field, but in this case I have a strictly enforced 1-1 relationship between the field I'm aggregating on and the other field I'm trying to get the value for.

This is how I'm currently accomplishing this, with a sub-aggregation:

"aggregations": {
    "example_aggregation": {
        "terms": {
            "size": 100,
            "field": "siteId"
        }
        "aggregations": {
            "siteTitle": {
                "terms": {
                    "field": "siteTitle"
                }
            }
        }
    }
}

Just to clarify, the 1-1 relationship that I'm talking about is between siteId and siteTitle. siteIds will only ever have one possible value for siteTitle, and vice-versa

The problem is that this is very slow. Without the sub-aggregation, results are returned about 7x faster.

Is there another way to accomplish this same thing? I'm using elastic search v. 1.5.2

Thanks in advance!


(system) #2