iMessage: How do I search for keywords in an individual message thread?
The archive of all the messages is in ~/Library/Messages/chat.db. It's a SQLite database. There are some SQLite viewers that will make it fairly easy to sort this data and either allow you to search it or selectively export some of it to CSV. Alternately if you search for "sqlite to csv" you'll find some more information on exporting it. Unfortunately this is a big weakness of iMessage.