Solr 响应中的内容类型

kgr*_*es2 3 html json solr

我一直在学习 Solr 并遇到了一个问题。如果我像这样向 Solr 查询:

curl "http://localhost:8983/solr/myCollection/select?q=*:*&wt=json&rows=0"
Run Code Online (Sandbox Code Playgroud)

我得到一个包含 JSON 响应的网页。但是,网页标题没有说明 Content-Type。

我想在标题中获取 Content-Type 以便查询 Solr 的人可以使用漂亮的打印工具来清理 Solr 响应并使其更具可读性,而不必一直提供“indent=on”选项。

有什么帮助吗?

谢谢

<html>
  <head>
    <link rel="alternate stylesheet" type="text/css"
     href="resource://gre-resources/plaintext.css"
     title="Wrap Long Lines">  
    <style type="text/css"></style>
  </head>
  <body>
    <pre>{"responseHeader":{"status":0,"QTime":0,"params":
         {"q":"*:*","rows":"0","wt":"json"}},"response":
         {"numFound":27394430,"start":0,"docs":[]}}
    </pre>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:感谢下面的答案,我把它修好了。我使用 Config API 进行了更改:

curl http://localhost:8983/solr/collectionName/config
  -H 'Content-Type:application/json' -d '{
  "update-queryresponsewriter" : {
    "name":"json",
    "class":"solr.JSONResponseWriter",
    "defaults": {
      "name":"application/json; charset=UTF-8"
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

请注意,更改不会立即对我生效,因此您可能需要等待一分钟才能显示更改。

Jan*_*nar 5

正如示例solrconfig.xml 所建议的,您应该Content-Type通过删除以下部分来修复:

  <queryResponseWriter name="json" class="solr.JSONResponseWriter">
    <!-- For the purposes of the tutorial, JSON responses are written as
     plain text so that they are easy to read in *any* browser.
     If you expect a MIME type of "application/json" just remove this override.
    -->
    <str name="content-type">text/plain; charset=UTF-8</str>
  </queryResponseWriter>
Run Code Online (Sandbox Code Playgroud)

没有 JSON 查看器的现代浏览器会将 JSON 显示为纯文本,因此除非您想在 IE6 之类的东西中查看数据,否则您会没事的。

通过http://grokbase.com/t/lucene/dev/1372n9jyha/solr-content-type-for-json发现