简体   繁体   English

如何在Apache Solr 6.5中检索和查询JSON类型字段

[英]How to Retrieve and Query JSON type fields in Apache Solr 6.5

My Goal is to retrieve JSON type fields in an Solr index and also perform search queries on such fields. 我的目标是在Solr索引中检索JSON类型的字段,并在此类字段上执行搜索查询。

I have the following documents in Solr Index and using the auto generated schema utilizing schemaless feature in Solr. 我在Solr索引中有以下文档,并在Solr中使用了利用无模式功能的自动生成模式。

POST http://localhost:8983/solr/test1/update?commitWithin=1000 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"}
 }
 ]

I see the JSON types are stored as strings in the schemaField type as seen in the output for following 我看到JSON类型以字符串形式存储在schemaField类型中,如以下输出所示

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

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

I had tried using srcField as mentioned in this post . 使用srcField在此提到的我试过 However, a query to retrieve json type returns empty response. 但是,检索json类型的查询返回空响应。 Below are the GET request used for the same 以下是用于同一请求的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&wt = json

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

Also, the search queries for values inside JSON type fields return empty response 另外,在JSON类型字段中搜索值的查询返回空响应

http://localhost:8983/solr/test1/select?q=pacman&wt=json HTTP://本地主机:8983 / solr的/ TEST1 /选择Q =吃豆&重量= JSON

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

Please help in searching object types in Solr. 请帮助在Solr中搜索对象类型。

Have you checked this: https://cwiki.apache.org/confluence/display/solr/Response+Writers 您是否检查过: https : //cwiki.apache.org/confluence/display/solr/Response+Writers

JSON Response Writer A very commonly used Response Writer is the JsonResponseWriter, which formats output in JavaScript Object Notation (JSON), a lightweight data interchange format specified in specified in RFC 4627. Setting the wt parameter to json invokes this Response Writer. JSON响应编写器 JsonResponseWriter是一种非常常用的响应编写器,它以JavaScript对象符号(JSON)格式格式化输出,这是RFC 4627中指定的轻量级数据交换格式。将wt参数设置为json会调用此响应编写器。 Here is a sample response for a simple query like q=id:VS1GB400C3&wt=json: 这是一个简单查询的示例响应,例如q = id:VS1GB400C3&wt = json:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM