build index and merge