我有以下 solrj 查询:
HttpSolrClient solr = new HttpSolrClient.Builder("http://10.xx.xxx.xxx:8983/solr").build();
solr.setParser(new XMLResponseParser());
SolrQuery query = new SolrQuery();
query.set("q", "*:*");
query.setFilterQueries("rt_tag:[2017-01-20T00:00:00Z TO NOW]","_relationship_:parent");
query.setFields("[child parentFilter=\"_relationship_:parent\"]","rt_*");
QueryResponse response = solr.query("rtm_aggregations_shard1_replica1", query);
SolrDocumentList docList = response.getResults();
当我执行此查询时,出现以下错误:
> ERROR SolrDispatchFilter null:java.lang.NullPointerException
> null:java.lang.NullPointerException at
> org.apache.solr.response.transform.ChildDocTransformer.transform(ChildDocTransformerFactory.java:137)
> at
> org.apache.solr.response.BinaryResponseWriter$Resolver.writeResultsBody(BinaryResponseWriter.java:159)
> at
> org.apache.solr.response.BinaryResponseWriter$Resolver.writeResults(BinaryResponseWriter.java:183)
> at
> org.apache.solr.response.BinaryResponseWriter$Resolver.resolve(BinaryResponseWriter.java:88)
> at
> org.apache.solr.common.util.JavaBinCodec.writeVal(JavaBinCodec.java:158)
> at
> org.apache.solr.common.util.JavaBinCodec.writeNamedList(JavaBinCodec.java:148)
> at
> org.apache.solr.common.util.JavaBinCodec.writeKnownType(JavaBinCodec.java:242)
> at
> org.apache.solr.common.util.JavaBinCodec.writeVal(JavaBinCodec.java:153)
> at
> org.apache.solr.common.util.JavaBinCodec.marshal(JavaBinCodec.java:96)
但是,直接按 http 执行相应的查询可以正常工作:
http://10.xx.xxx.xxx:8983/solr/rtm_aggregations_shard1_replica1/select?q=*:*&fq=rt_tag:[2017-01-20T00:00:00Z%20TO%20NOW]&fq=_relationship_:parent&fl=[child%20parentFilter=%22_relationship_:parent%22],rt_*
为什么它不能与 solrj 一起使用?
最佳答案
您无法将 Solrj 6.4.0 客户端与 Solr 4.10.3 一起使用。
这个版本的组合可以解释您遇到的问题。
javabin is a custom binary format used to write out solr's response in a fast and efficient manner.
根据我的经验,我建议使用完全相同版本的 Solrj。
在 Solrj 4.10.3 中,这是创建客户端的行:
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/");
更新
正如 @stefan.m 所建议的,即使使用版本 4.10.4,问题仍然出现。
检查后查看 source code ,您似乎遇到了错误。 这是Solr 4.x版本中ChildDocTransformerFactory.java类的第137行。
@Override
public void transform(SolrDocument doc, int docid) {
FieldType idFt = idField.getType();
Object parentIdField = doc.getFirstValue(idField.getName());
// *** line 137 ***
String parentIdExt = parentIdField instanceof IndexableField
? idFt.toExternal((IndexableField)parentIdField)
: parentIdField.toString();
这里有两个选项,我的意思是只有 idFt
或 parentIdField
可以为 null
。
我建议尝试在查询中添加 fl
参数,添加父 ID 字段。
关于java - solrj 子父关系查询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42027732/