我在Windows上使用Solr 7.2.1中的示例设置创建了一个示例SolrCloud实例:
bin/solr start -e cloud
bin/solr.cmd create -c trans -s 2 -rf 2
然后我更新了架构(因为大多数数据来自Postgres
和SQL Server
:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"trans",
"type":"string",
"stored":true,
"indexed":true},
"add-field":{
"name":"t",
"type":"pdate",
"stored":true,
"indexed":true},
"add-field":{
"name":"l",
"type":"pint",
"stored":true,
"indexed":true},
}' http://localhost:8983/solr/trans/schema
导致以下架构:
curl http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":0,
"QTime":0},
"fields":[{
"name":"_root_",
"type":"string",
"docValues":false,
"indexed":true,
"stored":false},
{
"name":"_text_",
"type":"text_general",
"multiValued":true,
"indexed":true,
"stored":false},
{
"name":"_version_",
"type":"plong",
"indexed":false,
"stored":false},
{
"name":"id",
"type":"string",
"multiValued":false,
"indexed":true,
"required":true,
"stored":true},
{
"name":"l",
"type":"pint",
"indexed":true,
"stored":true},
{
"name":"t",
"type":"pdate",
"indexed":true,
"stored":true},
{
"name":"trans",
"type":"string",
"indexed":true,
"stored":true}]}
在我们的例子中,ID的类型为uuid
。如果我改变它我会收到一个错误:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
"indexed":true}
}' http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":500,
"QTime":48},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
...
同时更改_root_
和id
无效:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
},
"replace-field":{
"name":"_root_",
"type":"uuid",
"stored":true,
"docValues":false,
"indexed":true,
"stored":false}
}
' http://localhost:8983/solr/trans/schema
{
"responseHeader":{
"status":500,
"QTime":50},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
如何正确更改solr中id
的类型?