具有子-父关系的 solrj 查询失败

solrj Query with child-parent relationsship fails

我有以下 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?

发送到 Solr 的查询如下:

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_*&wt=javabin

这个也失败了,但是在删除部分

时会 运行

&wt=javabin

我不知道这是什么原因,但解决方法是告诉 solrj 使用 XMLResponseParser:

solr.setParser(new XMLResponseParser());

使用此设置,效果很好。

您不能将 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 后,您似乎遇到了错误。 这是classChildDocTransformerFactory.java版本Solr4.x的第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 字段。