THM
THM

Reputation: 671

Is SOLR support complex types like structure for multiValued fields?

I need to add multiValued field which will be structure. Something like:

where:

class ComplexPhone [
    String area;
    String number;
    String internal;
    String type;
]

I want to receive this data from SOLR in json in format like this:

{
  "responseHeader": {
    "status": 0,
    "QTime": 1,
    "params": {
      "indent": "true",
      "q": "*:*",
      "_": "1394008742077",
      "wt": "json"
    }
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "first_name": "Funky",
        "last_name": "Koval",
        "phone": [
          {
             "area": "US",
             "number": "555-123-456-789",
             "internal": "011,
             "type": "S",

          },
          {
             "area": "UK",
             "number": "1234-5678",
             "internal": "9001",
             "type": "L",

          }
        ]
        "id": 1,
        "_version_": 1461724104955527200
      }
    ]
  }
}

This is only example ( I do not want to have only phone numbers ).

Most important for me is format of response from SOLR. I can add this data in any plain format like: Funky, Koval, UK; 1234-5678; 9001; L, US; 555-123-456-789; 011; S or

<doc>
<field name="first_name">Funky</field>
<field name="last_name">Koval</field>
<field name="phone">UK; 1234-5678; 9001; L</field>
<field name="phone">US; 555-123-456-789; 011; S</field>
<field name="id">1</field>
</doc>

It can be stored in SOLR as a string. All I need is response in more complicated format then flat structure mapped to JSON.

Any advice will be appreciated.

Upvotes: 6

Views: 2417

Answers (1)

buddy86
buddy86

Reputation: 1444

Solr supports multuValued fields. But it doesn't support multilevel data structure. You can not get the following type of response from Solr.

"phone": [
          {
             "area": "US",
             "number": "555-123-456-789",
             "internal": "011,
             "type": "S",

          },
          {
             "area": "UK",
             "number": "1234-5678",
             "internal": "9001",
             "type": "L",

          }

What multiValued field provides is like

"phone": [
          "UK",
          "1234-5678",
          "9001",
          "L"
        ]

Suggestions :

  1. You can design your data in a simpler manner so that, it can fit in Solr provided singlevalued/multivalued field.
  2. Keep your complex structured data in Solr as string or some suitable type of field. In your application parse the data to get the actual value.

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

Upvotes: 2

Related Questions