srilu
srilu

Reputation: 11

Solr schema with nested object

I am using solr 5.5 version in single instance. I am trying to index the below data as one record:

{
  "MLId": "00021BF6-BCC7-4F2E-8B8F-02587310A1B4",
  "PublishDate": "2015-06-03",
  "CompanyName": "GLI Finance Limited",
  "Ticker": "GLI",
  "Primary": "1",
  "Exchange": "Channel Islands Securities Exchange",
  "Line1": "Sarnia House",
  "Line2": "Le Truchot",
  "Line3": "St Peter Port",
  "Line4": "Guernsey GY1 4NA",
  "Line5": "Channel Islands",
  "Country": "GBR",
  "Phone": "",
  "WebAddress": "http://www.glifund.com",
  "NoOfEmployees": "",
  "Turnover": "580000",
  "TurnoverUSD": "992600.0000",
  "FinancialYearEnd": "--12--",
  "overView": "GLI Finance is a closed-ended investment company. It invests in senior secured loans and syndicated corporate loans issued primarily by middle market US companies. Its portfolio investment is managed by T2 Advisers. The company operates in the Channel Islands, the UK and the Cayman Islands. It is headquartered in St. Peter Port, Guernsey.|The company recorded revenues of £584.4 thousand (approximately $963.1 thousand) in the fiscal year ended December 2014. Its net loss was £13,626.4 thousand (approximately $22,457.6 thousand) in fiscal 2014.|",
  "MajorProductsServices": "GLI Finance is a closed-ended investment company. The company's key activities include the following: Activities: Invests in senior secured loans and syndicated corporate loans issued primarily by middle market US companies",
  "KeyEmployeesCount": "8",
  "_childDocuments_": [
    {
      "FullName": "Geoffrey Richard Miller",
      "JobTitle": "Chief Executive Officer and Executive Director",
      "Board": "Executive Board"
    },
    {
      "FullName": "Emma Stubbs",
      "JobTitle": "Chief Financial Officer",
      "Board": "Executive Board"
    },
    {
      "FullName": "Patrick Anthony Seymour Firth",
      "JobTitle": "Chairman",
      "Board": "Non Executive Board"
    },
    {
      "FullName": "Frederick Peter Forni",
      "JobTitle": "Non-Executive Director",
      "Board": "Non Executive Board"
    },
    {
      "FullName": "James Henry Carthew",
      "JobTitle": "Non-Executive Director",
      "Board": "Non Executive Board"
    },
    {
      "FullName": "Marc Krombach",
      "JobTitle": "Managing Director",
      "Board": "Senior Management"
    },
    {
      "FullName": "Andrew Whelan",
      "JobTitle": "Director, Lending",
      "Board": "Senior Management"
    },
    {
      "FullName": "Louise Beaumont",
      "JobTitle": "Head, Public Affairs and Marketing",
      "Board": "Senior Management"
    }
  ],
  "LocationsSubsidiariesCount": "5",
  "Subsidiary": [
    {
      "SubsidiaryName": "GLIF BMS Holdings Limited",
      "SubsidiaryAddressLine1": "",
      "SubsidiaryAddressLine2": "",
      "SubsidiaryAddressLine3": "",
      "SubsidiaryAddressLine4": "",
      "SubsidiaryAddressLine5": "",
      "SubsidiaryAddressCountry": "GBR"
    },
    {
      "SubsidiaryName": "Secured Loan Investments Limited",
      "SubsidiaryAddressLine1": "",
      "SubsidiaryAddressLine2": "",
      "SubsidiaryAddressLine3": "",
      "SubsidiaryAddressLine4": "",
      "SubsidiaryAddressLine5": "Guernsey",
      "SubsidiaryAddressCountry": "GBR"
    },
    {
      "SubsidiaryName": "BMS Finance AB Limited",
      "SubsidiaryAddressLine1": "",
      "SubsidiaryAddressLine2": "",
      "SubsidiaryAddressLine3": "",
      "SubsidiaryAddressLine4": "",
      "SubsidiaryAddressLine5": "",
      "SubsidiaryAddressCountry": "GBR"
    },
    {
      "SubsidiaryName": "NVF Tech Limited",
      "SubsidiaryAddressLine1": "",
      "SubsidiaryAddressLine2": "",
      "SubsidiaryAddressLine3": "",
      "SubsidiaryAddressLine4": "",
      "SubsidiaryAddressLine5": "",
      "SubsidiaryAddressCountry": "GBR"
    },
    {
      "SubsidiaryName": "GLI Investments Holdings Sarl",
      "SubsidiaryAddressLine1": "",
      "SubsidiaryAddressLine2": "",
      "SubsidiaryAddressLine3": "",
      "SubsidiaryAddressLine4": "",
      "SubsidiaryAddressLine5": "",
      "SubsidiaryAddressCountry": "LUX"
    }
  ]
}

I am getting Unknown command MLID error:

Could you please help me in creating the index?

Thanks, Srilu

Upvotes: 0

Views: 1881

Answers (1)

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

Short answer: put [] around that whole structure and it should work.

Long answer: Solr accepts JSON in 3 different forms:

  1. Single arbitrary JSON document that Solr does smart mapping to internal fields, creating them as needed (using schemaless) approach. The request handler for that is */update/json/docs" This works, but does not support children and also maps all new fields to multiValued types.
  2. Single arbitrary JSON document that Solr expects to be a sequence of commands, such as add, delete, and commit. This is in Solr-specific format and does support child documents. The request for that is "/update"
  3. A multi-document shortcut of the one above, where only the documents are provided in an array, including child support.

You are hitting the use case 2 here, so Solr is complaining that the first thing it sees is NOT one of the known commands. By putting you object into the array, you switch to type 3 and it should work.

P.s. Your specific example seems to have other arrays of nested objects which will probably stop indexing (specifically "Subsidiary"). But it is a separate problem/question.

Upvotes: 2

Related Questions