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 Georg Sorst <g....@findologic.com> on 2016/04/10 01:49:37 UTC

Set Config API user properties with SolrJ

Hi,

how can you set Config API values from SolrJ? Does anyone have an example
for this?

Here's what I'm currently trying:

/* Build the structure for the request */
Map<String, String> parameters = new HashMap<String, String>() {{
  put("key", "value");
}};
final NamedList<Object> requestParameters = new NamedList<>();
requestParameters.add("set-user-property", parameters);

/* Build the JSON */
CharArr json = new CharArr();
new SchemaRequestJSONWriter(json).write(requestParameters);
ContentStreamBase.StringStream stringStream = new
ContentStreamBase.StringStream(json.toString());
Collection<ContentStream> contentStreams = Collections.<ContentStream>
singletonList(stringStream);

/* Send the request */
GenericSolrRequest request = new
GenericSolrRequest(SolrRequest.METHOD.POST, "/config/overlay", null);
request.setContentStreams(contentStreams);
SimpleSolrResponse response = request.process(new HttpSolrClient("
http://localhost:8983/solr/test"));

The JSON is looking good, but it's doing... nothing. The response just
contains the default config-overlay contents (znodeVersion). Any idea why?

Thanks!
Georg
-- 
*Georg M. Sorst I CTO*
FINDOLOGIC GmbH



Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
E.: g.sorst@findologic.com
www.findologic.com Folgen Sie uns auf: XING
<https://www.xing.com/profile/Georg_Sorst>facebook
<https://www.facebook.com/Findologic> Twitter
<https://twitter.com/findologic>

Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
vereinbaren!
Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
vereinbaren!

Re: Set Config API user properties with SolrJ

Posted by Georg Sorst <g....@findologic.com>.
For further reference: I solved this by using an HTTP-based Solr in the
tests. Look at SolrTestCaseJ4.buildJettyConfig for more info

Georg Sorst <g....@findologic.com> schrieb am Mo., 11. Apr. 2016 um
10:28 Uhr:

> The issue is here:
>
> org.apache.solr.handler.SolrConfigHandler.handleRequestBody()
>
> This method will check the 'httpMethod' of the request. The
> set-user-property call will only be evaluated if the method is POST.
> Apparently, for non-HTTP requests this will never be true.
>
> I'll gladly write an issue / testcase / patch if someone can give me a
> little help.
>
> Georg Sorst <g....@findologic.com> schrieb am So., 10. Apr. 2016 um
> 14:36 Uhr:
>
>> Addendum: Apparently the code works fine with HttpSolrClient, but not
>> with EmbeddedSolrServer (used in our tests).The most recent version I
>> tested this was 5.5.0
>>
>> Georg Sorst <g....@findologic.com> schrieb am So., 10. Apr. 2016 um
>> 01:49 Uhr:
>>
>>> Hi,
>>>
>>> how can you set Config API values from SolrJ? Does anyone have an
>>> example for this?
>>>
>>> Here's what I'm currently trying:
>>>
>>> /* Build the structure for the request */
>>> Map<String, String> parameters = new HashMap<String, String>() {{
>>>   put("key", "value");
>>> }};
>>> final NamedList<Object> requestParameters = new NamedList<>();
>>> requestParameters.add("set-user-property", parameters);
>>>
>>> /* Build the JSON */
>>> CharArr json = new CharArr();
>>> new SchemaRequestJSONWriter(json).write(requestParameters);
>>> ContentStreamBase.StringStream stringStream = new
>>> ContentStreamBase.StringStream(json.toString());
>>> Collection<ContentStream> contentStreams = Collections.<ContentStream>
>>> singletonList(stringStream);
>>>
>>> /* Send the request */
>>> GenericSolrRequest request = new
>>> GenericSolrRequest(SolrRequest.METHOD.POST, "/config/overlay", null);
>>> request.setContentStreams(contentStreams);
>>> SimpleSolrResponse response = request.process(new HttpSolrClient("
>>> http://localhost:8983/solr/test"));
>>>
>>> The JSON is looking good, but it's doing... nothing. The response just
>>> contains the default config-overlay contents (znodeVersion). Any idea why?
>>>
>>> Thanks!
>>> Georg
>>> --
>>> *Georg M. Sorst I CTO*
>>> FINDOLOGIC GmbH
>>>
>>>
>>>
>>> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
>>> E.: g.sorst@findologic.com
>>> www.findologic.com Folgen Sie uns auf: XING
>>> <https://www.xing.com/profile/Georg_Sorst>facebook
>>> <https://www.facebook.com/Findologic> Twitter
>>> <https://twitter.com/findologic>
>>>
>>> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
>>> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
>>> vereinbaren!
>>> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
>>> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
>>> vereinbaren!
>>>
>> --
>> *Georg M. Sorst I CTO*
>> FINDOLOGIC GmbH
>>
>>
>>
>> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
>> E.: g.sorst@findologic.com
>> www.findologic.com Folgen Sie uns auf: XING
>> <https://www.xing.com/profile/Georg_Sorst>facebook
>> <https://www.facebook.com/Findologic> Twitter
>> <https://twitter.com/findologic>
>>
>> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
>> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
>> vereinbaren!
>> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
>> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
>> vereinbaren!
>>
> --
> *Georg M. Sorst I CTO*
> FINDOLOGIC GmbH
>
>
>
> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
> E.: g.sorst@findologic.com
> www.findologic.com Folgen Sie uns auf: XING
> <https://www.xing.com/profile/Georg_Sorst>facebook
> <https://www.facebook.com/Findologic> Twitter
> <https://twitter.com/findologic>
>
> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
> vereinbaren!
> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
> vereinbaren!
>
-- 
*Georg M. Sorst I CTO*
FINDOLOGIC GmbH



Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
E.: g.sorst@findologic.com
www.findologic.com Folgen Sie uns auf: XING
<https://www.xing.com/profile/Georg_Sorst>facebook
<https://www.facebook.com/Findologic> Twitter
<https://twitter.com/findologic>

Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
vereinbaren!
Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
vereinbaren!

Re: Set Config API user properties with SolrJ

Posted by Georg Sorst <g....@findologic.com>.
The issue is here:

org.apache.solr.handler.SolrConfigHandler.handleRequestBody()

This method will check the 'httpMethod' of the request. The
set-user-property call will only be evaluated if the method is POST.
Apparently, for non-HTTP requests this will never be true.

I'll gladly write an issue / testcase / patch if someone can give me a
little help.

Georg Sorst <g....@findologic.com> schrieb am So., 10. Apr. 2016 um
14:36 Uhr:

> Addendum: Apparently the code works fine with HttpSolrClient, but not with
> EmbeddedSolrServer (used in our tests).The most recent version I tested
> this was 5.5.0
>
> Georg Sorst <g....@findologic.com> schrieb am So., 10. Apr. 2016 um
> 01:49 Uhr:
>
>> Hi,
>>
>> how can you set Config API values from SolrJ? Does anyone have an example
>> for this?
>>
>> Here's what I'm currently trying:
>>
>> /* Build the structure for the request */
>> Map<String, String> parameters = new HashMap<String, String>() {{
>>   put("key", "value");
>> }};
>> final NamedList<Object> requestParameters = new NamedList<>();
>> requestParameters.add("set-user-property", parameters);
>>
>> /* Build the JSON */
>> CharArr json = new CharArr();
>> new SchemaRequestJSONWriter(json).write(requestParameters);
>> ContentStreamBase.StringStream stringStream = new
>> ContentStreamBase.StringStream(json.toString());
>> Collection<ContentStream> contentStreams = Collections.<ContentStream>
>> singletonList(stringStream);
>>
>> /* Send the request */
>> GenericSolrRequest request = new
>> GenericSolrRequest(SolrRequest.METHOD.POST, "/config/overlay", null);
>> request.setContentStreams(contentStreams);
>> SimpleSolrResponse response = request.process(new HttpSolrClient("
>> http://localhost:8983/solr/test"));
>>
>> The JSON is looking good, but it's doing... nothing. The response just
>> contains the default config-overlay contents (znodeVersion). Any idea why?
>>
>> Thanks!
>> Georg
>> --
>> *Georg M. Sorst I CTO*
>> FINDOLOGIC GmbH
>>
>>
>>
>> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
>> E.: g.sorst@findologic.com
>> www.findologic.com Folgen Sie uns auf: XING
>> <https://www.xing.com/profile/Georg_Sorst>facebook
>> <https://www.facebook.com/Findologic> Twitter
>> <https://twitter.com/findologic>
>>
>> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
>> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
>> vereinbaren!
>> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
>> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
>> vereinbaren!
>>
> --
> *Georg M. Sorst I CTO*
> FINDOLOGIC GmbH
>
>
>
> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
> E.: g.sorst@findologic.com
> www.findologic.com Folgen Sie uns auf: XING
> <https://www.xing.com/profile/Georg_Sorst>facebook
> <https://www.facebook.com/Findologic> Twitter
> <https://twitter.com/findologic>
>
> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
> vereinbaren!
> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
> vereinbaren!
>
-- 
*Georg M. Sorst I CTO*
FINDOLOGIC GmbH



Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
E.: g.sorst@findologic.com
www.findologic.com Folgen Sie uns auf: XING
<https://www.xing.com/profile/Georg_Sorst>facebook
<https://www.facebook.com/Findologic> Twitter
<https://twitter.com/findologic>

Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
vereinbaren!
Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
vereinbaren!

Re: Set Config API user properties with SolrJ

Posted by Georg Sorst <g....@findologic.com>.
Addendum: Apparently the code works fine with HttpSolrClient, but not with
EmbeddedSolrServer (used in our tests).The most recent version I tested
this was 5.5.0

Georg Sorst <g....@findologic.com> schrieb am So., 10. Apr. 2016 um
01:49 Uhr:

> Hi,
>
> how can you set Config API values from SolrJ? Does anyone have an example
> for this?
>
> Here's what I'm currently trying:
>
> /* Build the structure for the request */
> Map<String, String> parameters = new HashMap<String, String>() {{
>   put("key", "value");
> }};
> final NamedList<Object> requestParameters = new NamedList<>();
> requestParameters.add("set-user-property", parameters);
>
> /* Build the JSON */
> CharArr json = new CharArr();
> new SchemaRequestJSONWriter(json).write(requestParameters);
> ContentStreamBase.StringStream stringStream = new
> ContentStreamBase.StringStream(json.toString());
> Collection<ContentStream> contentStreams = Collections.<ContentStream>
> singletonList(stringStream);
>
> /* Send the request */
> GenericSolrRequest request = new
> GenericSolrRequest(SolrRequest.METHOD.POST, "/config/overlay", null);
> request.setContentStreams(contentStreams);
> SimpleSolrResponse response = request.process(new HttpSolrClient("
> http://localhost:8983/solr/test"));
>
> The JSON is looking good, but it's doing... nothing. The response just
> contains the default config-overlay contents (znodeVersion). Any idea why?
>
> Thanks!
> Georg
> --
> *Georg M. Sorst I CTO*
> FINDOLOGIC GmbH
>
>
>
> Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
> E.: g.sorst@findologic.com
> www.findologic.com Folgen Sie uns auf: XING
> <https://www.xing.com/profile/Georg_Sorst>facebook
> <https://www.facebook.com/Findologic> Twitter
> <https://twitter.com/findologic>
>
> Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!*
> Hier <beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
> vereinbaren!
> Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
> <beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
> vereinbaren!
>
-- 
*Georg M. Sorst I CTO*
FINDOLOGIC GmbH



Jakob-Haringer-Str. 5a | 5020 Salzburg I T.: +43 662 456708
E.: g.sorst@findologic.com
www.findologic.com Folgen Sie uns auf: XING
<https://www.xing.com/profile/Georg_Sorst>facebook
<https://www.facebook.com/Findologic> Twitter
<https://twitter.com/findologic>

Wir sehen uns auf dem *Shopware Community Day in Ahaus am 20.05.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20SCD> Termin
vereinbaren!
Wir sehen uns auf der* dmexco in Köln am 14.09. und 15.09.2016!* Hier
<beratung@findologic.com?subject=Terminvereinbarung%20dmexco> Termin
vereinbaren!