1

We are trying to create/upload new synonyms to Solr as managed resources. We are facing some problems when we create multi-term synonyms like, for example, "United States of America" or "Spider Man". The Solr Documentation provides a curl command example for single-term synonyms but doesn't have a curl command example for multi-term.

We tried the following command and some variants:

1)

`curl -X POST -H "Content-type:application/json" ... --data-binary "["ARS","Argentinian Peso"]"`

2)

curl -X POST -H "Content-type:application/json" ... --data-binary '["ARS","Argentinian Peso"]'

3)

curl -X POST -H "Content-type:application/json" ... --data-binary [["ARS","Argentinian Peso"]]

For the three we got the following errors:

1)

{
  "responseHeader":{
    "status":500,
    "QTime":2},
  "error":{
    "msg":"Expected ',' or ']': char=(EOF),position=16 BEFORE='[ARS,Argentinian'",
    "trace":"org.noggit.JSONParser$ParseException: Expected ',' or ']': char=(EOF),position=16 BEFORE='[ARS,Argentinian'\n\tat org.noggit.JSONParser.err(JSONParser.java:356)...",
    "code":500}}

curl: (3) [globbing] unmatched close brace/bracket in column 5

2)

{
  "responseHeader": {
    "status": 500,
    "QTime": 2
  },
  "error": {
    "msg": "Bad Request",
    "trace": "Bad Request (400) - Unsupported update format java.lang.String\n\tat org.apache.solr.rest.ManagedResource.doPut(ManagedResource.java:410)...",
    "code": 500
  }
}

3)

{
  "responseHeader": {
    "status": 500,
    "QTime": 2
  },
  "error": {
    "msg": "Expected ',' or ']': char=P,position=18 BEFORE='[[ARS,Argentinian P' AFTER='eso]]'",
    "trace": "org.noggit.JSONParser$ParseException: Expected ',' or ']': char=P,position=18 BEFORE='[[ARS,Argentinian P' AFTER='eso]]'\n\tat org.noggit.JSONParser.err(JSONParser.java:356)...",
    "code": 500
  }
}

After we tried to create them from json file with success; we used the following curl command:

4)

curl -X POST -H "Content-type:application/json" ... --data-binary @synonyms_test.json

The synonyms_test.json has:

["USA","United States of America"]

After we tried to extend this 'workaround' because we need to create/upload thousands of synonyms to an existing collection. Then we decide to fill the json file with array of arrays (a valid json content):

[["aaa", "aaa1"],["bbb", "bbb1"]]

And the result was:

4)

{
  "responseHeader": {
    "status": 500,
    "QTime": 2
  },
  "error": {
    "msg": "java.util.ArrayList cannot be cast to java.lang.String",
    "trace": "java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String ...",
    "code": 500
  }
}

Do you have any idea how to solve this?

Regards, DM

2 Answers2

0

According to the documentation an example is the following

curl -X PUT -H 'Content-type:application/json' --data-binary '["funny", "entertaining", "whimiscal", "jocular"]' "http://localhost:8983/solr/techproducts/schema/analysis/synonyms/english"

Which is the same as your number 2 example, except you are using POST not PUT. Try using PUT and see if that helps.

Also,

[["aaa", "aaa1"],["bbb", "bbb1"]]

is not a valid because you can only PUT an array of strings. To add multiple symmetric synonym groups, you will have to do one call for each array.

Andrew Daniel
  • 688
  • 1
  • 5
  • 7
0

Running below command will enable to add stopwords.

curl -X PUT -H 'Content-type:application/json' --data-binary \
 '{"class":"org.apache.solr.rest.schema.analysis.ManagedWordSetResource"}' \
 "http://localhost:8983/solr/techproducts/schema/analysis/stopwords/english"