【问题标题】:Is SOLR support complex types like structure for multiValued fields?SOLR 是否支持复杂类型,例如多值字段的结构?
【发布时间】:2014-03-06 21:53:34
【问题描述】:

我需要添加多值字段,这将是结构。 比如:

地点:

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

我想从 SOLR 以 json 格式接收这些数据,格式如下:

{
  "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
      }
    ]
  }
}

这只是一个例子(我不想只有电话号码)。

对我来说最重要的是 SOLR 的响应格式。 我可以以任何普通格式添加这些数据,例如: Funky,Koval,英国; 1234-5678; 9001; L,美国; 555-123-456-789; 011;小号 或

<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>

它可以作为字符串存储在 SOLR 中。 我所需要的只是以更复杂的格式响应,然后是映射到 JSON 的平面结构。

我们将不胜感激。

【问题讨论】:

    标签: json types solr structure


    【解决方案1】:

    Solr 支持 multuValued 字段。但它不支持多级数据结构。您无法从 Solr 获得以下类型的响应。

    "phone": [
              {
                 "area": "US",
                 "number": "555-123-456-789",
                 "internal": "011,
                 "type": "S",
    
              },
              {
                 "area": "UK",
                 "number": "1234-5678",
                 "internal": "9001",
                 "type": "L",
    
              }
    

    multiValued 字段提供的是什么

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

    建议:

    1. 您可以以更简单的方式设计数据,使其适合 Solr 提供的单值/多值字段。
    2. 在 Solr 中将复杂的结构化数据保存为字符串或某些合适类型的字段。在您的应用程序中解析数据以获取实际值。

    您可以参考What is the use of "multiValued" field type in Solr?

    【讨论】:

      猜你喜欢
      • 2021-10-14
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 2016-09-09
      相关资源
      最近更新 更多