SPOILERS Getting Necrozma takes some time. After defeating the Elite 4 and becoming the first champion of Alola, you'll get a letter from a man outside of your house that says to go to the motel in route 8.
You'll meet Anabel and Looker. They'll tell you about the Ultra Beasts, then they'll send you on a mission to catch each and every one of them. (Note that there will sometimes be more than one to catch).
Once you complete these missions, go to the motel on route 2 and talk to Looker. He'll tell you that he thought he saw Necrozma, but he thinks it was just his imagination.
Finally, go to the farthest hollow in Ten Carat Hill, put on a Max Repel, and run around in the grass until you encounter Necrozma.
Necrozma is NOT an Ultra Beast, so don't use any Beast Balls on it.
This video Will also help you.