This question is a duplicate of How can we use importance sampling for drawing posterior distribution samples? , but that question seems to lack additional detail and goes unanswered (for more than 2 years). So I am posting this question with more contexts.
Given a hard to sample $p(x)$, which can be e.g. a posterior, we can estimate its $E_{p}[x]$ by using $E_{q}\left[\frac{p(x)}{q(x)}x\right]$, where $q(x)$ is a easy to sample distribution, and has support that contains the support of $p$.
My question is, can we use a similar idea to sample from $p(x)$? Specifically, we can draw samples from $q(x)$, and let's call them $x_1, ..., x_n$. We can compute weight $w_1, ... w_n$ with $w_i=p(x_i)/q(x_i)$. Then we do a weighted sampling with replacement (bootstrapping?) from $x_1, ..., x_n$, with weight being $w_i$'s, i.e., we sample $y_i$ from $x_1, ..., x_n$ according the categorical distribution with weight $w_1, ..., w_n$. Then will those $y_i$ be distributed according to $p(x)$?
My intuitive concern is that $y_i$ will contain lots of duplicates, especially if the weights are not close to uniform. However, we are pretty much guaranteed that we will not encounter duplicate samples from any continuous distribution. So $y_i$ feels weird to me if they are distributed as $p(x)$.