Created
April 12, 2018 20:37
-
-
Save pandurx/ac67949a365e1cd012c5b0f7fd320ff7 to your computer and use it in GitHub Desktop.
This file contains 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
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