indexingfull-text-searchsolrmultivalue

What is the use of "multiValued" field type in Solr?


I'm new to Apache Solr. Even after reading the documentation part, I'm finding it difficult to clearly understand the functionality and use of the multiValued field type property.

What internally Solr does/treats/handles a field that is marked as multiValued?

What is the difference in indexing in Solr between a field that is multiValued and those that are not?

Can somebody explain with some good example?

Doc says:

multiValued=true|false

True if this field may contain multiple values per document, i.e. if it can appear multiple times in a document


Solution

  • A multivalued field is useful when there are more than one value present for the field. An easy example would be tags, there can be multiple tags that need to be indexed. so if we have tags field as multivalued then solr response will return a list instead of a string value. One point to note is that you need to submit multiple lines for each value of the tags like:

    <field name="tags">tag1</tags>
    <field name="tags">tag2</tags>
    ...
    <field name="tags">tagn</tags>
    

    Once you have all the values index you can search or filter results by any value, e,g. you can find all documents with tag1 using query like

    q=tags:tag1
    

    or use the tags to filter out results like

    q=query&fq=tags:tag1