2017-06-01 56 views
0

我的目标是检索Solr索引中的JSON类型字段,并对这些字段执行搜索查询。如何检索和查询Apache Solr中的JSON类型字段6.5

我在Solr索引中使用以下文档,并使用Solr中使用无模式特性的自动生成模式。

POST http://localhost:8983/solr/test1/update?commitWithin=1000

[ 
    {"id" : "1", "type_s":"book", "title_t" : "The Way of Kings", "author_s" : "Brandon Sanderson", 
"miscinfo": {"provider": "orielly", "site": "US"} 
}, 
{"id" : "2", "type_s":"book", "title_t" : "The Game of Thrones", "author_s" : "James Sanderson", 
"miscinfo": {"provider": "pacman", "site": "US"} 
} 
] 

我看到了JSON类型存储为所看到的输出以下

GET http://localhost:8983/solr/test1/schema/fields

{ 
     "name":"miscinfo", 
     "type":"strings"} 

我用曾试图在schemaField类型字符串如post中所述的srcField。但是,检索json类型的查询将返回空响应。下面是用于相同

GET请求GET http://localhost:8983/solr/test1/select?q=1&fl=miscinfo&wt=json

GET http://localhost:8983/solr/test1/select?q=1&fl=miscinfo,source_s:[json]&wt=json

另外,JSON类型字段内的值的搜索查询返回空响应

http://localhost:8983/solr/test1/select?q=pacman&wt=json

{ 
    "responseHeader": { 
    "status": 0, 
    "QTime": 0, 
    "params": { 
     "q": "pacman", 
     "json": "", 
     "wt": "json" 
    } 
    }, 
    "response": { 
    "numFound": 0, 
    "start": 0, 
    "docs": [] 
    } 
} 

请帮助搜索Solr中的对象类型。

回答

0

你检查这一点:https://cwiki.apache.org/confluence/display/solr/Response+Writers

JSON响应作家一个非常常用的响应作家是 JsonResponseWriter,其格式输出以JavaScript对象符号 (JSON),一种轻量级的数据交换格式指定在RFC 4627中的指定 中。将wt参数设置为json调用此响应 Writer。下面是一个简单的查询的响应示例像 Q = ID:VS1GB400C3 &重量= JSON:

+0

我已经检查这个链接,并已经在使用重量= JSON获得JSON响应。不过,我在从JSON类型的索引数据中检索字段时遇到了问题。 – FindingTheOne

+0

我看到的唯一区别是indent = true,但我不认为这应该是原因...在这里搜索我发现这个: https://cwiki.apache.org/confluence/display/solr/Transforming+和+索引+自定义+ JSON 它设置为:“-H'内容类型:应用程序/ json'-d'” – leonardo

+0

是的,我没有看到任何添加indent = true后的输出差异HTTP请求 – FindingTheOne