Created
September 13, 2013 14:02
-
-
Save erikhatcher/6551152 to your computer and use it in GitHub Desktop.
Splitting key1:value1;key2:value2 strings from an incoming field and making them individual fields
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
function processAdd(cmd) { | |
doc = cmd.solrDoc; // org.apache.solr.common.SolrInputDocument | |
id = doc.getFieldValue("id"); | |
logger.info("update-script#processAdd: id=" + id); | |
kvString = doc.removeField("kv").getValue(); | |
kvs = kvString.split(";"); | |
for(i=0; i < kvs.length; i++) { | |
kv = kvs[i].split(":"); | |
doc.setField(kv[0] + "_s", kv[1]); | |
} | |
// Index a doc with "kv" field set: http://localhost:8983/solr/collection1/update/csv?stream.contentType=text/csv&stream.body=1,k1:v1;k2:v2&fieldnames=id,kv&update.chain=script&commit=true | |
// Results in this document in the index: | |
// { | |
// "responseHeader":{ | |
// "status":0, | |
// "QTime":2, | |
// "params":{ | |
// "q":"*:*"}}, | |
// "response":{"numFound":1,"start":0,"docs":[ | |
// { | |
// "id":"1", | |
// "k1_s":"v1", | |
// "k2_s":"v2", | |
// "_version_":1446071014026903552}] | |
// }} | |
} | |
function processDelete(cmd) { | |
// no-op | |
} | |
function processMergeIndexes(cmd) { | |
// no-op | |
} | |
function processCommit(cmd) { | |
// no-op | |
} | |
function processRollback(cmd) { | |
// no-op | |
} | |
function finish() { | |
// no-op | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment