AWS CloudSearch file/data upload using JDK – code sample
Yet another post to help others both cut to the chase as well as understand a new bit of technology, this one is about using the AWS java JDK for communicating with and in this case, uploading a file to a cloudsearch Domain.
I’ll be brief. This one took a while for me as the javadocs were not, to me, reflecting the way the code behaved. In the end, one gotcha i can clue you in on is that there is now a cloudsearch2 package. I did not use that new one, but that doesn’t mean you shouldn’t. Just don’t get yourself wrapped around the axel about the documentation’s reference to a endPointConfiguration object. This quick version simply didn’t need one.
In the end our snippet below is quite straight forward. It simply :
- sets up the credentials
- feeds them to our client object
- identifies the endpoint and region strings ( in simple examples like this one you simply use the web AWS Console to create your CS domain).
- use Java i/o functions to create a stream to your simple json file
- and fire away!
You can then go and check your results back in the AWS web console, it gives you a good UI for testing your domain’s records.
Note here that I just made up the ID value. You can figure out your own schema when you do your homework. 🙂
There are many other standard fields as you can find in the documentation. And, you can add your own, as I have with the coid and minimumUserLevel fields. They are properly indexed fields which you can filter your results on as well.