当我使用order子句执行查询时,系统会抛出这样的异常
无法对多值字段进行排序:DATE"。
所有字段类型都会出现这种情况,例如string,long等。
我使用Solr Schema浏览器分析了字段,并且所有字段都有 multivalue = true; 用于标记"属性"和"架构"。 (图片atached )
我以这种方式插入文档,使用java代码:
String solrPath = Configuration.getString("solr.path");
HttpSolrClient solr = new HttpSolrClient(solrPath);
SolrInputDocument document = new SolrInputDocument();
document.addField("CATEGORY", knowError.getCategory().getDescription());
document.addField("RAITING", knowError.getRaiting()); //long value
document.addField("DATE", knowError.getRevisionDate());
UpdateRequest req = new UpdateRequest();
req.setAction(UpdateRequest.ACTION.COMMIT, false, false);
req.add(document);
UpdateResponse response = req.process(solr);
solr.commit();
我以这种方式进行查询:
String solrPath = Configuration.getString("solr.path");
HttpSolrClient client = new HttpSolrClient(solrPath);
client.setUseMultiPartPost(true);
client.setConnectionTimeout(5000);
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(key);
solrQuery.setFields("KEDB_ID", "CAUSE", "SOLUTION", "WORKAROUND", "CATEGORY","DESCRIPTION","AUTHOR","TAGS","RAITING","DATE");
solrQuery.setStart(0);
solrQuery.setRows(200);
if(filterByRaiting){
solrQuery.addSort("RAITING", SolrQuery.ORDER.desc);
}else (filterByDate)
{
solrQuery.addSort("DATE", SolrQuery.ORDER.desc);
}
//solrQuery.addSort(SolrQuery.SortClause.asc("CAUSE"));
QueryResponse response = client.query(solrQuery);
ret= response.getResults();
如何在插入中创建 multivalue = false 字段?
答案 0 :(得分:0)
也许您之前可以在架构文件中定义一些dynamic fields
,例如
<dynamicField name="*_i" type="slong" indexed="true" stored="true" multiValued="false" />
以这种方式插入文件,用java代码:
document.addField("RAITING_i", knowError.getRaiting()); //long value