0
votes

I have a scenario where I would like to dynamically assign incoming document fields to two different solr schema fieldTypes. One fieldType will be an 'exact match' fieldType while the other will be a 'full text' fieldType. The fields will follow a predictable pattern but the pattern can not be recognized using the dynamicField type and will not be known ahead of time.

So here is an example of the field names that I need to be able to process:

FOO_BAR_TEXT_1

FOO_BAR_TEXT_2

WIDGET_BAR_TEXT_3

WIDGET_BAR_TEXT_4

--

FOO_BAR_SELECT_1

FOO_BAR_SELECT_2

WIDGET_BAR_SELECT_1

The above fields will not be defined in advance. I need to map all fields with the name _BAR_SELECT_ to a fieldType of 'exactMatch' and I need to map all of the fields with name _BAR_TEXT_ to a fieldType of 'fulltext'. I was hoping there might be a way of doing this dynamically when the document is indexed.

2

2 Answers

0
votes

Have you tried using solr dynamic fields?

https://cwiki.apache.org/confluence/display/solr/Dynamic+Fields

Basically it would look something like this:

Obviously you'd need to make your own definitions (or use an existing one) for the types.

0
votes

It is currently not possible to create fields like *_BAR_SELECT_*.

In the old solr wiki, as well as in the collection1 schema.xml file the is a restriction mentioned for dynamic fields:

RESTRICTION: the glob-like pattern in the name attribute must have a "*" only at the start or the end.


However, if you change the name to, say, BAR_SELECT_*, than it will be possible to dynamicly create fields "BAR_TEXT_FOO_1", "BAR_TEXT_FOO_2", "BAR_TEXT_WIDGET_3", and so on.

Like this:

<dynamicField name="BAR_TEXT_*" type="fulltext" />
<dynamicField name="BAR_SELECT_*" type="exactMatch" />