I am considering [positive] charge distributions $\rho:M\rightarrow\mathbb{R}_+$ (nonnegative reals) with unit charge $\int_M\rho=1$ for convenience. Here $M$ is a nice-enough region, say a submanifold of $\mathbb{R}^n$ (or perhaps simply a metric space ?).
The electrostatic energy is (up to constant factor) $W=\int_M\rho V$, where $V(r)=\frac{\rho(r)}{r}$ is the potential at distance $r$. We can rewrite this $W=\int_M \frac{\rho(x)\rho(x')}{|x-x'|}dx\ dx'$.