user1025397
user1025397

Reputation: 67

solr data import default values

I am working with solr. in database indexing is there a way i can give default value to a field in data config file itself. I cannot give the default value in schema.xml because my value depends on table so it has to be done in data config file.

Upvotes: 2

Views: 1646

Answers (3)

Zouzias
Zouzias

Reputation: 2360

Yes, it is possible.

You have to specify the default value in the schema.xml file. For example,

<field name="myFileWithDefaultValue" type="string" stored="true" indexed="true" default="default_value_string_here"/>

Reference:

Solr Schema.xml Description

Upvotes: 2

Jayendra
Jayendra

Reputation: 52789

You can add it to the sql query itself.
And as you would know the table you are firing the query on when defining the entity, the value can be changed.

select 'Annual' as datatype, i.* from item i

And field type defination -

<field column="datatype" name="datatype" />

Upvotes: 1

The Bndr
The Bndr

Reputation: 13394

If you indexing as database - by using data import handler, you could use MySQL features to return an default value, if the filed is (for example) empty.

You could use the IFNULL or CASE. Look at this: http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html

An other way is to use UNION on MySQL: http://dev.mysql.com/doc/refman/5.1/en/union.html

COALESCE is also an option: http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_coalesce

Upvotes: 2

Related Questions