Last active
September 6, 2015 11:00
-
-
Save andrew-dixon/27788b7c730dff66875f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// Query to retrieve some data from the database | |
variables.myData = queryExecute( | |
sql = " | |
SELECT * | |
FROM myTable | |
LIMIT 10 | |
", | |
options = {datasource="#Application.myDSN#"} | |
); | |
// Loop over the array and insert each into ElasticSearch using the HTTP Put API call | |
for (i in variables.myData) { | |
// The ElasticSearch server is local and the data is going into myIndex using myType and an ID from the database | |
http method="put" url="http://localhost:9200/myIndex/myType/#i.myID#" result="putRequest" { | |
// Pass a JSON serialize string into the ElasticSearch as the document to be added to the index | |
httpparam type="body" value="#SerializeJSON(i)#"; | |
}; | |
// Dump the returned structure for information | |
dump(variables.putRequest); | |
writeOutput("<br><br>") | |
} | |
</cfscript> |
You can simplif this by just doing the query and then using
for (row in query) {}
railo will give you a struct for each row.
@d1rtym0nk3y: queryRowToStruct is meant to be a UDF / global thing, but you're right, if this is all on the same page, he could simplify.
@d1rtym0nk3y - I swear I tried that and it didn't work, will try it again... Thanks.
@d1rtym0nk3y - Yep, that worked fine, I have updated the gist to show this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above example retrieve 10 rows of data from a database table to puts them into an ElasticSearch index.
The above code is for Railo 4.1+