Hi Alex,

Solr 4.10 has support to create fields (of already defined types) with its Schema API:
https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-Modifytheschema

But one has to specify an initial schema.xml which is shared forever between all cores created from the same config.

To create cores with a real managed schema, I think I'd need one of the following non-existing features

a) a "create core from template" core admin request which creates a core from a config set by copying the schema instead of sharing it b) a "create core with schema" core admin request where the schema fields are submitted by the caller c) a Schema API request to a core must not modify the schema of the linked config set but copy the schema to the core before modification. The config set's schema should only be modified if the Schema API request is send to an URL representing the config set.
d) or something else ;-)

I can use dynamic fields as a workaround. And I will do that for now.

Thank you,
Andreas


Alexandre Rafalovitch wrote on 11/07/2014 05:59 PM:
The usual solution to that is to have dynamic fields with suffixes
indicating the types. So, your int fields are mapped to *_i, your date
fields to *_d.

Solr has schemaless support, but it is auto-detect for now. Creating
fields of particular types via API I think is in JIRA on the trunk for
5.0.

Regards,
    Alex.
Personal: http://www.outerthoughts.com/ and @arafalov
Solr resources and newsletter: http://www.solr-start.com/ and @solrstart
Solr popularizers community: https://www.linkedin.com/groups?gid=6713853


On 6 November 2014 10:04, Andreas Hubold <andreas.hub...@coremedia.com> wrote:
Hi,

I have a use-case where Java applications need to create Solr indexes
dynamically. Schema fields of these indexes differ and should be defined by
the Java application upon creation.

So I'm trying to use the Core Admin API [1] to create new cores and the
Schema API [2] to define fields. When creating a core, I have to specify
solrconfig.xml (with enabled ManagedIndexSchemaFactory) and the schema to
start with. I thought it would be a good idea to use a named config sets [3]
for this purpose:

curl
'http://localhost:8082/solr/admin/cores?action=CREATE&name=m1&instanceDir=cores/m1&configSet=myconfig&dataDir=data'

But when I add a field to the core "m1", the field actually gets added to
the config set. Is this a bug of feature?

curl http://localhost:8082/solr/m1/schema/fields -X POST -H
'Content-type:application/json'
   --data-binary '[{
         "name":"foo",
         "type":"tdate",
         "stored":true
     }]'

All cores created from the config set "myconfig" will get the new field
"foo" in their schema. So this obviously does not work to create cores with
different schema.

I also tried to use the config/schema parameters of the CREATE core command
(instead of config sets) to specify some existing solrconfig.xml/schema.xml.
I tried relative paths here (e.g. some level upwards) but I could not get it
to work. The documentation [1] tells me that relative paths are allowed.
Should this work?

Next thing that would come to my mind is to use dynamic fields instead of a
correct managed schema, but that does not sound as nice.
Or maybe I should implement a custom CoreAdminHandler which takes list of
field definitions, if that's possible somehow...?

I don't know. What's your recommended approach?

We're using Solr 4.10.1 non-SolrCloud. Would this be simpler or different
with SolrCloud?

Thank you,
Andreas

[1]
https://cwiki.apache.org/confluence/display/solr/CoreAdmin+API#CoreAdminAPI-CREATE
[2]
https://cwiki.apache.org/confluence/display/solr/Schema+API#SchemaAPI-Modifytheschema
[3] https://cwiki.apache.org/confluence/display/solr/Config+Sets
.


Reply via email to