Normalized Histograms

Say you are plotting a bar plot of top n items occurring in index 'A'. Additional information about these items, such as length of the item, is present in index 'B'. Plot a normalized histogram of count/length.

Can you give more details on how a document/item looks like in the index?

The document in index A looks as follows:

"id" : 100032,
"name": 'Abcssd',
"properties": ['g1','g2','g3','g4','g5']

The document in index B looks as follows:

"id" : 123,
"name": 'g1',
"length" : 10

I want a plot with gi on the x-axis and the (count of docs in index A containing gi)/(length of gi) on y-axis.

I know that joins are not possible in Elastic search, If this length information is sitting in an external database (postgres or a json file) , can it be accessed during the rendereing of the visualization?