solr-node-client icon indicating copy to clipboard operation
solr-node-client copied to clipboard

Update function fails: "msg":"Unknown command 'id' at [5]"

Open LaughingBubba opened this issue 3 years ago • 1 comments

Hi there, I'm not sure if I'm invoking the update() function correctly or not. The add() function works. Interestingly though, the add() seems to work like a replace????

There's no example of an update in the docs either.

Running the code below >>>

const solr = require('solr-client')

const solr_client = solr.createClient({host:'localhost', core:'test'})

const items = [
	{id: 1, text:'apple'},
	{id: 2, text:'orange'},
	{id: 3, text:'pears, oranges and apples'}
]

main()

async function main() {
	console.log("add:", await solr_client.add(items))
	console.log("commit:", await solr_client.commit())
	
	console.log("update:", await solr_client.update({id: 3, text:'cantaloupe'}))
	console.log("commit:", await solr_client.commit())
}

/*
Update schema:   
curl -X POST -H 'Content-type:application/json' --data-binary '{
  "add-field": [
  {
	"name": "text",
	"type": "text_general"
	"indexed": true,
	"required": true,
  }]
}' http://localhost:8983/solr/test/schema
*/

Results in this output:

add: { responseHeader: { status: 0, QTime: 31 } }
commit: { responseHeader: { status: 0, QTime: 119 } }
/Users/xxxxx/Projects/xxxxx/node_modules/solr-client/dist/lib/solr.js:152
            throw new Error(`Request HTTP error ${response.statusCode}: ${text}`);
                  ^

Error: Request HTTP error 400: {
  "responseHeader":{
    "status":400,
    "QTime":0},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"Unknown command 'id' at [5]",
    "code":400}}

    at Client.doRequest (/Users/xxxxx/Projects/xxxxx/node_modules/solr-client/dist/lib/solr.js:152:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async main (/Users/xxxxx/Projects/xxxxx/src/test_solr.js:18:25)

Node.js v17.3.0

LaughingBubba avatar Jan 12 '22 06:01 LaughingBubba

Never mind. I don't need to update as I proved that solr "upserts" documents a'la mongo. I ditched the client when I realised its a wrapper for some fairly simple REST calls back to the solr server. superagent was sufficient for my needs.

eg:

await superagent
	.post('http://localhost:8983/solr/mycore/update?commit=true')
	.set('Content-type', 'application/json')
	.send({add: solr_docs})

LaughingBubba avatar Jan 18 '22 05:01 LaughingBubba