Re: Solr7 embeded req: Bad content type error

2018-08-29 Thread Alfonso Noriega
Thanks for your time and help Andrea,
I guess we should try to use the Json API
<https://lucene.apache.org/solr/guide/7_4/json-request-api.html> provided
by Solr and figure out a way to do so with SolrJ.


On Wed, 29 Aug 2018 at 14:21, Andrea Gazzarini  wrote:

> Well, I don't know the actual reason why the behavior is different
> between Cloud and Embedded client: maybe things are different because in
> the Embedded Solr HTTP is not involved at all, but I'm just shooting in
> the dark.
>
> I'm not aware about POST capabilities you mentioned, sorry
>
> Andrea
>
>
> On 29/08/2018 14:07, Alfonso Noriega wrote:
> > Yes, I realized that changing the method to GET solves the issue but it
> is
> > intentionally set to POST as in a real case scenario we had the issue of
> > users creating too long queries which where facing the REST length
> limits.
> > I think a possible solution would be to send the Solr params as a json in
> > the request body, but I am not sure if SolrJ supports this.
> >
> > Alfonso.
> >
> > On Wed, 29 Aug 2018 at 13:46, Andrea Gazzarini 
> wrote:
> >
> >> I think that's the issue: just guessing because I do not have the code
> >> in front of me.
> >>
> >> POST requests put the query in the request body, and the
> >> EmbeddedSolrServer expects to find a valid JSON. Did you try to remove
> >> the Method param?
> >>
> >> Andrea
> >>
> >>
> >> On 29/08/2018 13:12, Alfonso Noriega wrote:
> >>> Hi Andrea,
> >>>
> >>> Thanks for your help, something which is relevant and I forgot to
> mention
> >>> before is that the requests are always a POST method.
> >>> As mentioned before, it is not a single query which fails but all of
> the
> >>> requests done to the  search handler.
> >>>
> >>> final SolrQuery q = new SolrQuery("!( _id_:"+
> doc.getId()+")AND(_root_:"+
> >>> doc.getId()+")");
> >>> final QueryResponse query = solrClient.query(q,
> SolrRequest.METHOD.POST);
> >>>
> >>> Regarding the embedded server instantiation:
> >>> .
> >>> .
> >>> .
> >>> final CoreContainer container =
> CoreContainer.createAndLoad(tmpSolrHome,
> >>> tmpSolrConfig);
> >>> return new SolrClientWrapper(container, CORE_NAME, tmpSolrHome);
> >>> .
> >>> .
> >>> .
> >>> private class SolrClientWrapper extends EmbeddedSolrServer {
> >>>
> >>>   private final Path temporaryFolder;
> >>>
> >>>   public SolrClientWrapper(CoreContainer coreContainer, String
> >>> coreName, Path temporaryFolder) {
> >>>   super(coreContainer, coreName);
> >>>   this.temporaryFolder = temporaryFolder;
> >>>   }
> >>> .
> >>> .
> >>> .
> >>>
> >>> The whole embedded server instantiation can be seen here
> >>> <
> >>
> https://github.com/RBMHTechnology/vind/blob/master/server/embedded-solr-server/src/main/java/com/rbmhtechnology/vind/solr/backend/EmbeddedSolrServerProvider.java
> >>> .
> >>>
> >>> Best,
> >>> Alfonso.
> >>>
> >>> On Wed, 29 Aug 2018 at 12:57, Andrea Gazzarini 
> >> wrote:
> >>>> Hi Alfonso,
> >>>> could you please paste an extract of the client code? Specifically
> those
> >>>> few lines where you create the SolrQuery with params.
> >>>>
> >>>> The line you mentioned is dealing with ContentStream which as far as I
> >>>> remember wraps the request body, and not the request params. So as
> >>>> request body Solr expects a valid JSON payload, but in your case, if I
> >>>> got you, you're sending plain query parameters (through SolrJ).
> >>>>
> >>>> Best,
> >>>> Andrea
> >>>>
> >>>> On 29/08/2018 12:45, Alfonso Noriega wrote:
> >>>>> Hi,
> >>>>> I am implementing a migration of Vind
> >>>>> <https://github.com/RBMHTechnology/vind> library from solr 5 to
> 7.4.0
> >>>> and I
> >>>>> am facing an error which I have no idea how to solve...
> >>>>>
> >>>>> The library provides a wrapper (and some extra stuff) to develop
> search
> >>>>&

Re: Solr7 embeded req: Bad content type error

2018-08-29 Thread Alfonso Noriega
Yes, I realized that changing the method to GET solves the issue but it is
intentionally set to POST as in a real case scenario we had the issue of
users creating too long queries which where facing the REST length limits.
I think a possible solution would be to send the Solr params as a json in
the request body, but I am not sure if SolrJ supports this.

Alfonso.

On Wed, 29 Aug 2018 at 13:46, Andrea Gazzarini  wrote:

> I think that's the issue: just guessing because I do not have the code
> in front of me.
>
> POST requests put the query in the request body, and the
> EmbeddedSolrServer expects to find a valid JSON. Did you try to remove
> the Method param?
>
> Andrea
>
>
> On 29/08/2018 13:12, Alfonso Noriega wrote:
> > Hi Andrea,
> >
> > Thanks for your help, something which is relevant and I forgot to mention
> > before is that the requests are always a POST method.
> > As mentioned before, it is not a single query which fails but all of the
> > requests done to the  search handler.
> >
> > final SolrQuery q = new SolrQuery("!( _id_:"+ doc.getId()+")AND(_root_:"+
> > doc.getId()+")");
> > final QueryResponse query = solrClient.query(q, SolrRequest.METHOD.POST);
> >
> > Regarding the embedded server instantiation:
> > .
> > .
> > .
> > final CoreContainer container = CoreContainer.createAndLoad(tmpSolrHome,
> > tmpSolrConfig);
> > return new SolrClientWrapper(container, CORE_NAME, tmpSolrHome);
> > .
> > .
> > .
> > private class SolrClientWrapper extends EmbeddedSolrServer {
> >
> >  private final Path temporaryFolder;
> >
> >  public SolrClientWrapper(CoreContainer coreContainer, String
> > coreName, Path temporaryFolder) {
> >  super(coreContainer, coreName);
> >  this.temporaryFolder = temporaryFolder;
> >  }
> > .
> > .
> > .
> >
> > The whole embedded server instantiation can be seen here
> > <
> https://github.com/RBMHTechnology/vind/blob/master/server/embedded-solr-server/src/main/java/com/rbmhtechnology/vind/solr/backend/EmbeddedSolrServerProvider.java
> >
> > .
> >
> > Best,
> > Alfonso.
> >
> > On Wed, 29 Aug 2018 at 12:57, Andrea Gazzarini 
> wrote:
> >
> >> Hi Alfonso,
> >> could you please paste an extract of the client code? Specifically those
> >> few lines where you create the SolrQuery with params.
> >>
> >> The line you mentioned is dealing with ContentStream which as far as I
> >> remember wraps the request body, and not the request params. So as
> >> request body Solr expects a valid JSON payload, but in your case, if I
> >> got you, you're sending plain query parameters (through SolrJ).
> >>
> >> Best,
> >> Andrea
> >>
> >> On 29/08/2018 12:45, Alfonso Noriega wrote:
> >>> Hi,
> >>> I am implementing a migration of Vind
> >>> <https://github.com/RBMHTechnology/vind> library from solr 5 to 7.4.0
> >> and I
> >>> am facing an error which I have no idea how to solve...
> >>>
> >>> The library provides a wrapper (and some extra stuff) to develop search
> >>> tools over Solr and uses SolrJ to access it, more info about it can be
> >> seen
> >>> in the public repo, but basically all requests are done to solr
> through a
> >>> client provided by solrj.
> >>> Actually, the migration is done and the tests running against a cloud
> >>> instance are working perfectly fine. The issue arises when testing
> >> against
> >>> an embedded server (which is the default case as you may not have a
> local
> >>> solr instance running), in which case every request fails throwing the
> >>> following exception:
> >>> *org.apache.solr.common.SolrException: Bad contentType for search
> handler
> >>> :application/javabin request={q=!(+_id_:P3)AND(_root_:P3)}*
> >>>
> >>> * at
> >>>
> >>
> org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:73)*
> >>> * at
> >>>
> >>
> org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)*
> >>> * at
> >>>
> >>
> org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)*
> >>> * at org.apache.solr.core.SolrCore.execute(SolrCore.java:2539)*
> >>> * at
> >>>
> >>
> org.apache.solr.client.solrj.embedd

Re: Solr7 embeded req: Bad content type error

2018-08-29 Thread Alfonso Noriega
Hi Andrea,

Thanks for your help, something which is relevant and I forgot to mention
before is that the requests are always a POST method.
As mentioned before, it is not a single query which fails but all of the
requests done to the  search handler.

final SolrQuery q = new SolrQuery("!( _id_:"+ doc.getId()+")AND(_root_:"+
doc.getId()+")");
final QueryResponse query = solrClient.query(q, SolrRequest.METHOD.POST);

Regarding the embedded server instantiation:
.
.
.
final CoreContainer container = CoreContainer.createAndLoad(tmpSolrHome,
tmpSolrConfig);
return new SolrClientWrapper(container, CORE_NAME, tmpSolrHome);
.
.
.
private class SolrClientWrapper extends EmbeddedSolrServer {

private final Path temporaryFolder;

public SolrClientWrapper(CoreContainer coreContainer, String
coreName, Path temporaryFolder) {
super(coreContainer, coreName);
this.temporaryFolder = temporaryFolder;
}
.
.
.

The whole embedded server instantiation can be seen here
<https://github.com/RBMHTechnology/vind/blob/master/server/embedded-solr-server/src/main/java/com/rbmhtechnology/vind/solr/backend/EmbeddedSolrServerProvider.java>
.

Best,
Alfonso.

On Wed, 29 Aug 2018 at 12:57, Andrea Gazzarini  wrote:

> Hi Alfonso,
> could you please paste an extract of the client code? Specifically those
> few lines where you create the SolrQuery with params.
>
> The line you mentioned is dealing with ContentStream which as far as I
> remember wraps the request body, and not the request params. So as
> request body Solr expects a valid JSON payload, but in your case, if I
> got you, you're sending plain query parameters (through SolrJ).
>
> Best,
> Andrea
>
> On 29/08/2018 12:45, Alfonso Noriega wrote:
> > Hi,
> > I am implementing a migration of Vind
> > <https://github.com/RBMHTechnology/vind> library from solr 5 to 7.4.0
> and I
> > am facing an error which I have no idea how to solve...
> >
> > The library provides a wrapper (and some extra stuff) to develop search
> > tools over Solr and uses SolrJ to access it, more info about it can be
> seen
> > in the public repo, but basically all requests are done to solr through a
> > client provided by solrj.
> > Actually, the migration is done and the tests running against a cloud
> > instance are working perfectly fine. The issue arises when testing
> against
> > an embedded server (which is the default case as you may not have a local
> > solr instance running), in which case every request fails throwing the
> > following exception:
> > *org.apache.solr.common.SolrException: Bad contentType for search handler
> > :application/javabin request={q=!(+_id_:P3)AND(_root_:P3)}*
> >
> > * at
> >
> org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:73)*
> > * at
> >
> org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)*
> > * at
> >
> org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)*
> > * at org.apache.solr.core.SolrCore.execute(SolrCore.java:2539)*
> > * at
> >
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.request(EmbeddedSolrServer.java:191)*
> > * at
> org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:194)*
> > * at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:974)*
> > * at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:990)*
> >
> > After some debugging I have seen that the embedded solr server uses
> > *org.apache.solr.request.json.RequestUtil* to process the parameters
> which
> > invariable expects a '*application/json' *contentType but SolrJ prodcues
> as
> > *'application/javabin'.*
> > Any ideas on how to fix this issue?
> >
> > The library has in the pom defined the following solr depedencies :
> > *.*
> > *.*
> > *.*
> >
> > *7.4.0*
> > *.*
> > *.*
> > *.*
> > **
> > *org.apache.solr*
> > *solr-core*
> > *${solr.version}*
> > **
> > **
> > *org.apache.solr*
> > *solr-solrj*
> > *${solr.version}*
> > **
> >
> > Thanks!
>
>

-- 
-- 
Alfonso Noriega
Software engineer
Redlink GmbH
e: alfonso.nori...@redlink.co 
w: http://redlink.co


Solr7 embeded req: Bad content type error

2018-08-29 Thread Alfonso Noriega
Hi,
I am implementing a migration of Vind
<https://github.com/RBMHTechnology/vind> library from solr 5 to 7.4.0 and I
am facing an error which I have no idea how to solve...

The library provides a wrapper (and some extra stuff) to develop search
tools over Solr and uses SolrJ to access it, more info about it can be seen
in the public repo, but basically all requests are done to solr through a
client provided by solrj.
Actually, the migration is done and the tests running against a cloud
instance are working perfectly fine. The issue arises when testing against
an embedded server (which is the default case as you may not have a local
solr instance running), in which case every request fails throwing the
following exception:
*org.apache.solr.common.SolrException: Bad contentType for search handler
:application/javabin request={q=!(+_id_:P3)AND(_root_:P3)}*

* at
org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:73)*
* at
org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)*
* at
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)*
* at org.apache.solr.core.SolrCore.execute(SolrCore.java:2539)*
* at
org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.request(EmbeddedSolrServer.java:191)*
* at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:194)*
* at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:974)*
* at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:990)*

After some debugging I have seen that the embedded solr server uses
*org.apache.solr.request.json.RequestUtil* to process the parameters which
invariable expects a '*application/json' *contentType but SolrJ prodcues as
*'application/javabin'.*
Any ideas on how to fix this issue?

The library has in the pom defined the following solr depedencies :
*.*
*.*
*.*

*7.4.0*
*.*
*.*
*.*
**
*org.apache.solr*
*solr-core*
*${solr.version}*
**
**
*org.apache.solr*
*solr-solrj*
*${solr.version}*
**

Thanks!
-- 
Alfonso Noriega
Software engineer
Redlink GmbH
e: alfonso.nori...@redlink.co 
w: http://redlink.co


Re: Filter Must/Must not clauses and parenthesis

2018-05-08 Thread Alfonso Noriega
Thanks Shawn!

I was not thinking of it as a subtraction but it makes all the sense put
like that.

On 8 May 2018 at 17:55, Shawn Heisey <apa...@elyograg.org> wrote:

> On 5/8/2018 4:02 AM, Alfonso Noriega wrote:
>
>>   I found solr 5.5.4 is doing some unexpected behavior (at least
>> unexpected
>> for me) when using Must and Must not operator and parenthesis for
>> filtering
>> and it would be great if someone can confirm if this is unexpected or not
>> and why.
>>
>
> 
>
> Do you have any idea why is this happening?
>>
>
> I'm surprised ANY of those examples are working.  While the bug that Erick
> mentioned could be a problem, I think this is happening because you've got
> a multi-clause pure negative query. All query clauses have NOT attached to
> them.  Purely negative queries do not actually work.
>
> The reason negative queries don't work is that if you start with nothing
> and then start subtracting things, you end up with nothing.
>
> To properly work, the first example would need to be written like this:
>
> *:* AND NOT(status:"DELETED") AND (*:* AND NOT(length:[186+TO+365])
> AND NOT(length:[366+TO+*]))
>
> I have added the all documents query as the starting point for both major
> clauses, so that the subtraction (AND NOT) has something to subtract from.
> Some of those parentheses are unnecessary, but I have preserved them in the
> rewritten query.Without unnecessary parentheses/quotes, the query would
> look like this:
>
> *:* AND NOT status:DELETED AND (*:* AND NOT length:[186+TO+365]
> AND NOT length:[366+TO+*])
>
> You might be wondering why something like "fq=-status:DELETED" will work
> even though it's a purely negative query. This works because with a
> super-simple query like that, Solr is able to detect the unworkable
> situation and automatically fix it by adding the all-docs starting point
> behind the scenes. The example you gave is too complicated for Solr's
> detection to work, so it doesn't get fixed.
>
> Thanks,
> Shawn
>
>


-- 
-- 
Alfonso Noriega
Software engineer
Redlink GmbH
e: alfonso.nori...@redlink.co <sergio.fernan...@redlink.co>
w: http://redlink.co


Filter Must/Must not clauses and parenthesis

2018-05-08 Thread Alfonso Noriega
Hi everyone,
 I found solr 5.5.4 is doing some unexpected behavior (at least unexpected
for me) when using Must and Must not operator and parenthesis for filtering
and it would be great if someone can confirm if this is unexpected or not
and why.

To clarify I will write an example:
The following problematic query should give results but it is actually not
giving anyi
q=*:*=edismax=NOT(status:"DELETED")+AND+(NOT(length:[186+TO+365])+AND+NOT(length:[366+TO+*]))
which is parsed as -dynamic_multi_stored_facet_string_static_status:DELETED
+(-dynamic_multi_stored_facet_long_core_length:[186 TO 365]
-dynamic_multi_stored_facet_long_core_length:[366 TO *])

If I rewrite the query removing the enclosing parentheses as
q=*:*=edismax=NOT(status:"DELETED")+AND+NOT(length:[186+TO+365])+AND+NOT(length:[366+TO+*]))
is parsed as -dynamic_multi_stored_facet_string_static_status:DELETED
-dynamic_multi_stored_facet_long_core_length:[186 TO 365]
-dynamic_multi_stored_facet_long_core_length:[366 TO *]
and it gives the expected results.

Again if the parenthesis enclosed condition is alone as
q=*:*=edismax=(NOT(length:[186+TO+365])+AND+NOT(length:[366+TO+*]))
it is pased as (-dynamic_multi_stored_facet_long_core_length:[186 TO
365] -dynamic_multi_stored_facet_long_core_length:[366 TO *]) and
giving more results.

Do you have any idea why is this happening?

Thanks for your help,
Alfonso.

-- 
Alfonso Noriega
Software engineer
Redlink GmbH
e: alfonso.nori...@redlink.co <sergio.fernan...@redlink.co>
w: http://redlink.co