Stats aggregation using two or more fields


(Mykola Borysiuk) #1

Hi.

I have aggregations like this

"aggs":{
	"fandex_lists":{"terms":{"field":"lists","size":5},
		"aggs":{
			"fandex_overall":{
				"stats":{"field": "scores.fandex.overall.value" }
			}
		}
	}
}

"aggs":{
	"fandex_lists":{"terms":{"field":"lists","size":5},
		"aggs":{
			"revenue_overall":{
				"stats":{"field": "revenue.overall.total" }
			}
		}
	}
}

As you can see those two aggregations uses same terms field to match documents, just have different stats field to collect results.

I have a question about stats aggregation.

Can i collect stats for both fields in same query like so

   "aggs":{
    	"fandex_lists":{"terms":{"field":"lists","size":5},
    		"aggs":{
    			"overall":{
    				"stats":{"field": "scores.fandex.overall.value" },
                    "stats":{"field": "revenue.overall.total" }
    			}
    		}
    	}
    }

Or something similar. I read documentation and try to google but cant find solution. Maybe im missing something obvious.

Thank you.


(Colin Goodheart-Smithe) #2

Yes, you can. The following should get you what you want:

   "aggs":{
    	"fandex_lists":{"terms":{"field":"lists","size":5},
    		"aggs":{
    			"overall":{
    				"stats":{"field": "scores.fandex.overall.value" }
    			},
                "fandex": {
                    "stats":{"field": "revenue.overall.total" }
                }
    		}
    	}
    }

Hope that helps


(Mykola Borysiuk) #3

Damn... I tried like that :D. Just don't check results correctly.

Thank you very much.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.