You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Mikhail Edoshin <mi...@onegasoft.com> on 2020/12/08 14:12:02 UTC

Can I express this nested query in JSON DSL?

Hi,

I'm more or less new to Solr. I need to run queries that use joins all 
over the place. (The idea is to index database records pretty much as 
they are and then query them in interesting ways and, most importantly, 
get the rank. Our dataset is not too large so the performance is great.)

I managed to express the logic using the following approach. For 
example, I want to search people by their names or addresses:

   q=type:Person^=0 AND ({!edismax qf=<personFields> v=$p0} OR {!join 
<personToAddress> v=$p1})
   p1={!edismax qf=<addressFields> v=p0}
   p0=<queryText>

(Here 'type:Person' works as a filter so I zero its score.) This seems 
to work as expected and give the right results and ranking. It also 
seems to scale nicely for two levels of joins, although the queries 
become rather hard to follow in their raw form (I used a custom 
XML-to-query transformer to actually formulate more complex queries).

So my question is that: can I express an equivalent query using the 
query DSL? I know I can use 'bool' like that:

{
   "query": {
      "bool" : {
         "must" : [ ... ];
         "should" : [ ... ]
       }
    }
  }

But how do I actually go from 'x AND (y OR z)' to 'bool' in the query 
DSL? I seem to lose the nice compositional properties of the expression. 
Here, for example, the expression implies that at least 'y' or 'z' must 
match; I don't quite see how I can express this in the DSL.

Kind regards,
Mikhail

Re: Can I express this nested query in JSON DSL?

Posted by Mikhail Khludnev <mk...@apache.org>.
Hi, Mikhail.
Shouldn't be a big deal
"bool":{
     "must":[ "x",
            {"bool":
                 {"should":["y","z"]}}]
}

On Tue, Dec 8, 2020 at 6:13 AM Mikhail Edoshin <mi...@onegasoft.com>
wrote:

> Hi,
>
> I'm more or less new to Solr. I need to run queries that use joins all
> over the place. (The idea is to index database records pretty much as
> they are and then query them in interesting ways and, most importantly,
> get the rank. Our dataset is not too large so the performance is great.)
>
> I managed to express the logic using the following approach. For
> example, I want to search people by their names or addresses:
>
>    q=type:Person^=0 AND ({!edismax qf=<personFields> v=$p0} OR {!join
> <personToAddress> v=$p1})
>    p1={!edismax qf=<addressFields> v=p0}
>    p0=<queryText>
>
> (Here 'type:Person' works as a filter so I zero its score.) This seems
> to work as expected and give the right results and ranking. It also
> seems to scale nicely for two levels of joins, although the queries
> become rather hard to follow in their raw form (I used a custom
> XML-to-query transformer to actually formulate more complex queries).
>
> So my question is that: can I express an equivalent query using the
> query DSL? I know I can use 'bool' like that:
>
> {
>    "query": {
>       "bool" : {
>          "must" : [ ... ];
>          "should" : [ ... ]
>        }
>     }
>   }
>
> But how do I actually go from 'x AND (y OR z)' to 'bool' in the query
> DSL? I seem to lose the nice compositional properties of the expression.
> Here, for example, the expression implies that at least 'y' or 'z' must
> match; I don't quite see how I can express this in the DSL.
>
> Kind regards,
> Mikhail
>


-- 
Sincerely yours
Mikhail Khludnev