在Solr上索引json,它被索引为List而不是项目

时间:2014-01-21 14:44:36

标签: json solr indexing solr4

我正在尝试索引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,我只添加了我需要的新字段。

有人可以向我解释如何在没有[]?

的情况下索引元素

由于

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分: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 :(得分:0)

看起来您遇到与嵌套Jsons相关的问题,您可以使用 -

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

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