Skip to content

Instantly share code, notes, and snippets.

@pandurx
Created April 12, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandurx/ac67949a365e1cd012c5b0f7fd320ff7 to your computer and use it in GitHub Desktop.
Save pandurx/ac67949a365e1cd012c5b0f7fd320ff7 to your computer and use it in GitHub Desktop.
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
// retrieve the json text from the api (elgg)
URL apiURL = new URL("http://192.168.1.18/gcconnex/services/api/rest/json/?method=get.entity_list&type=object&subtype=blog")
def slurper = new JsonSlurper()
def api_response = slurper.parseText(apiURL.text)
def results = api_response.result
for (result in results) {
def title = result.title
def description = result.description
// build the json string and curl post to solr
def json_string = new JsonBuilder(["guid": result.guid, "title": "$title", "description": "$description", "type": "$result.type", "subtype": "$result.subtype", "access_id": result.access_id])
def process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" --data-binary '" + json_string.toString() + "' http://192.168.1.18:8983/solr/elgg-core/update/json/docs?commit=true" ].execute().text
println process
//http://192.168.1.18:8983/solr/elgg-core/select?q=title:please&q=description:please
}
/*
<field name="guid" type="int" indexed="true" stored="false" required="true" />
<field name="title" type="text_general" indexed="true" stored="true" />
<field name="description" type="text_general" indexed="true" stored="true" />
<field name="type" type="text_general" indexed="true" stored="true" />
<field name="subtype" type="text_general" indexed="true" stored="true" />
<field name="access_id" type="int" indexed="true" stored="true" />
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment