2014-01-21 31 views
0

我想索引一个JSON文件在Solr中,它的工作原理,但我不明白为什么Solr索引元素作为一个数组而不是元件。Solr索引json,它索引为列表而不是作为项目

当我索引示例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,这里我只补充说,我需要的新领域。

有人可以向我解释我如何做索引没有[]的元素?

感谢

+1

您可以编辑您的问题,并补充说,核心的'schema.xml'? – cheffe

+0

完成后,我将它上传到pastebin –

回答

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)模式中的向上滚动,你可以读到这个代表

多值:如果该字段可能每个文档

包含多个值

你可以阅读这是什么好,什么后果在几个来源

+0

ouch,这很容易。谢谢 :) –

1

您已设置为多值这两个字段(标题,递减),这就是为什么,这样做,如果他们有一个值:

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