I have a Solr Core with Parent-Child Documents and I want to build dynamic Querys to search those documents.
I'm using Spring-Data-solr
and want to use the Criteria-Class to build such queries for searching specific child documents and receiving the full parent + children I use Block-Join-Parent Query.
Working query example:
q {!parent which=object_type:shipping_order}invoicenumber:31920000
fl *,[child parentFilter=object_type:shipping_order]
I tried different things to concat this criteria-objects to build such a query but I don't find a good way.
Here is an try to build such a query in Spring-Data-Solr
, but it does not work.
Criteria invoiceNumberCritera= new Criteria("invoicenumber").is("31920000");
Criteria doctypeCriteria = new Criteria("doctype").is("Invoice");
SimpleQuery query = new SimpleQuery("{!parent which=object_type:shipping_order}");
query.addCriteria(invoiceNumberCritera);
query.addCriteria(doctypeCriteria);
query.addProjectionOnField(new SimpleField("*"));
query.addProjectionOnField(new SimpleField("[child parentFilter=object_type:shipping_order]"));
StackTrace:
Caused by: org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: org.apache.solr.search.SyntaxError: Cannot parse ' AND invoiceNumber:31920000 AND doctype:Invoice': Encountered " <AND> "AND "" at line 1, column 1.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
<BAREOPER> ...
"(" ...
"*" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
<REGEXPTERM> ...
"[" ...
"{" ...
<LPARAMS> ...
"filter(" ...
<NUMBER> ...
<TERM> ...
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:649) ~[solr-solrj-8.1.1.jar:8.1.1 fcbe46c28cef11bc058779afba09521de1b19bef - ab - 2019-05-22 15:20:04]
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:255) ~[solr-solrj-8.1.1.jar:8.1.1 fcbe46c28cef11bc058779afba09521de1b19bef - ab - 2019-05-22 15:20:04]
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:244) ~[solr-solrj-8.1.1.jar:8.1.1 fcbe46c28cef11bc058779afba09521de1b19bef - ab - 2019-05-22 15:20:04]
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:207) ~[solr-solrj-8.1.1.jar:8.1.1 fcbe46c28cef11bc058779afba09521de1b19bef - ab - 2019-05-22 15:20:04]
at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:1019) ~[solr-solrj-8.1.1.jar:8.1.1 fcbe46c28cef11bc058779afba09521de1b19bef - ab - 2019-05-22 15:20:04]
at org.springframework.data.solr.core.SolrTemplate.lambda$executeSolrQuery$9(SolrTemplate.java:519) ~[spring-data-solr-4.0.9.RELEASE.jar:4.0.9.RELEASE]
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:167) ~[spring-data-solr-4.0.9.RELEASE.jar:4.0.9.RELEASE]
... 68 common frames omitted
Is there a good way to use Block-Join-Parent Query's in Spring-Data-Solr? Like a Criteria-object where i can add other Criterias like
Criteria fieldCriteria = Criteria.where("invoiceNumber").is("300230");
blockJoinCritera.addCriteria(fieldCriteria);