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 巩学超 <xu...@qunar.com> on 2016/04/11 13:58:35 UTC

How to set multivalued false, using SolrJ

Hello,
         Can you do me a favour, I use solrJ to index, but I get all the Field is multivalued. How can I set my Field to not multivalued, can you tell me how to setting use solrJ.


Re: How to set multivalued false, using SolrJ

Posted by Shawn Heisey <ap...@elyograg.org>.
On 4/11/2016 7:40 AM, Charles Sanders wrote:
> Multivalued fields are controlled by the schema. You need to define your field in the schema file as 'not' a multivalue field. Here are a couple of examples of field definitions, one multivalued, the other not. 
>
> <field name="component" type="string" indexed="true" stored="false" multiValued="true"/> 
> <field name="environment" type="text_general" indexed="true" stored="false" /> 
>
> If you do not explicitly define your field, then solr will use default definitions, which are probably storing the field as multivalued. 

Also, make sure that the schema version (a parameter within the schema
itself, NOT the Solr version) is high enough.  If this parameter is set
to 1.0 *all* fields are multivalued.  If you do not include the version
parameter at all, it will default to 1.0.  (Devs: should we change this
to default to whatever the current highest version is?  Defaulting to
*ancient* tech seems like a bad thing.)

Here's the comment near the top of the techproducts example schema from
Solr 5.5.0:

  <!-- attribute "name" is the name of this schema and is only used for
display purposes.
       version="x.y" is Solr's version number for the schema syntax and
       semantics.  It should not normally be changed by applications.

       1.0: multiValued attribute did not exist, all fields are multiValued
            by nature
       1.1: multiValued attribute introduced, false by default
       1.2: omitTermFreqAndPositions attribute introduced, true by default
            except for text fields.
       1.3: removed optional field compress feature
       1.4: autoGeneratePhraseQueries attribute introduced to drive
QueryParser
            behavior when a single string produces multiple tokens. 
Defaults
            to off for version >= 1.4
       1.5: omitNorms defaults to true for primitive field types
            (int, float, boolean, string...)
       1.6: useDocValuesAsStored defaults to true.
     -->

Thanks,
Shawn


Re: How to set multivalued false, using SolrJ

Posted by Charles Sanders <cs...@redhat.com>.
Hello, 
Multivalued fields are controlled by the schema. You need to define your field in the schema file as 'not' a multivalue field. Here are a couple of examples of field definitions, one multivalued, the other not. 

<field name="component" type="string" indexed="true" stored="false" multiValued="true"/> 
<field name="environment" type="text_general" indexed="true" stored="false" /> 

If you do not explicitly define your field, then solr will use default definitions, which are probably storing the field as multivalued. 


Charles 





----- Original Message -----

From: "巩学超" <xu...@qunar.com> 
To: solr-user@lucene.apache.org 
Sent: Monday, April 11, 2016 7:58:35 AM 
Subject: How to set multivalued false, using SolrJ 

Hello, 
Can you do me a favour, I use solrJ to index, but I get all the Field is multivalued. How can I set my Field to not multivalued, can you tell me how to setting use solrJ. 



Re: How to set multivalued false, using SolrJ

Posted by Chris Hostetter <ho...@fucit.org>.
:          Can you do me a favour, I use solrJ to index, but I get all the 
:          Field is multivalued. How can I set my Field to not 
:          multivalued, can you tell me how to setting use solrJ.

If you are using a "Managed Schema" (which was explicitly configured in 
most Solr 5.x exampleconfigs, and is now the implicit default in Solr 6) 
you can use the Schema API to make these changes.  There is also a 
"SchemaRequest" convinience class for this if you are a SolrJ user...

https://cwiki.apache.org/confluence/display/solr/Schema+API
https://lucene.apache.org/solr/5_5_0/solr-solrj/org/apache/solr/client/solrj/request/schema/SchemaRequest.html

SolrClient client = ...;
SchemaRequest req = new SchemaRequest.ReplaceField(...);
...
req.process(client)




-Hoss
http://www.lucidworks.com/