Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LaughingBubba opened this issue Jan 12, 2022 · 1 comment
Open

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

LaughingBubba opened this issue Jan 12, 2022 · 1 comment

Comments

@LaughingBubba
Copy link

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
Copy link
Author

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})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant