A shallow earthquake brought down hundreds of poorly built buildings in Indonesia, forcing more than 2,000 people to flee their homes, rescue officials said on Thursday.