【问题标题】:Indexing json on Solr, it indexed as a List instead of as an item在 Solr 上索引 json,它被索引为列表而不是项目
【发布时间】:2014-02-11 05:35:00
【问题描述】:

我正在尝试在 Solr 中为 JSON 文件编制索引并且它可以工作,但我不明白为什么 Solr 将元素索引为数组而不是元素。

当我索引示例 json 文件“books.json”时,它工作正常,但如果我索引另一个文件“items.json”,它会生成不同的输出。

我在下面显示:

Books.json

 [{
    "id" : "978-0641723445",
    "cat" : ["book","hardcover"],
    "name" : "The Lightning Thief",
    "author" : "Rick Riordan",
    "series_t" : "Percy Jackson and the Olympians",
    "sequence_i" : 1,
    "genre_s" : "fantasy",
    "inStock" : true,
    "price" : 12.50,
    "pages_i" : 384
  }]

 OUTPUT

{
    "id": "978-0641723445",
    "cat": [
      "book",
      "hardcover"
     ],
    "name": "The Lightning Thief",
    "author": "Rick Riordan",
    "author_s": "Rick Riordan",
    "series_t": "Percy Jackson and the Olympians",
    "sequence_i": 1,
    "genre_s": "fantasy",
    "inStock": true,
    "price": 12.5,
    "price_c": "12.5,USD",
    "pages_i": 384,
    "_version_": 1457847842153431000
},

Items.json

[{ 
    "title" : "Pruebas Carlos",
    "id" : 14,
     "desc" : "Probando como funciona el campo de descripciones"
}]

OUTPUT

{
    "title": [
       "Pruebas Carlos"
    ],
    "id": "10",
    "desc": [
      "Probando como funciona el campo de descripciones"
    ],
    "_version_": 1457849881416695800
},

My Schema,我只添加了我需要的新字段。

有人可以向我解释如何在没有 [] 的情况下索引元素吗?

谢谢

【问题讨论】:

  • 您能否编辑您的问题并添加该核心的schema.xml
  • 完成,我上传到 pastebin

标签: json solr indexing solr4


【解决方案1】:

简而言之,这些字段由您的架构配置为数组,这就是为什么将它们作为 JSON 数组写入响应的原因。即使他们的样本中只有一个成员。

如果它们只是单值,则需要将它们配置为multiValued="false"


您担心的字段 titledesc 配置为 multiValued="true",正如您在架构的摘录中看到的那样

<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="desc" type="text_general" indexed="true" stored="true" multiValued="true"/>

如果您在架构中向上滚动一点(到第 82 行),您可以阅读这代表什么

multiValued:如果此字段可能包含每个文档的多个值,则为 true

您可以从多个来源了解这有什么好处以及后果是什么

【讨论】:

  • 哎呀,这很容易。谢谢:)
【解决方案2】:

您已将两个字段(标题、描述)设置为多值,这就是为什么,如果它们只有一个值,请执行此操作:

<field name="desc" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="title" type="text_general" indexed="true" stored=" true" multiValued="false"/>

【讨论】:

    【解决方案3】:

    看起来你有一个与嵌套 Json 相关的问题,你可以使用 -

    (i) /solr/update/json?commit=true?split=/&f=txt:/**

    (ii) 使用索引处理程序 - https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2016-08-04
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 2017-07-06
      • 2023-03-15
      • 2017-09-07
      相关资源
      最近更新 更多