Solr返回的JSON [英] JSON returned by Solr

查看:145
本文介绍了Solr返回的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Solr来索引我的数据.

I'm using Solr in order to index my data.

通过Solr的用户界面,我在Schema窗口中添加了两个字段:word,messageid

Through the Solr's UI I added, in the Schema window, two fields: word, messageid

在我发表以下查询帖子后:

After I made the following query post:

curl -X POST -H "Content-Type: application/json" 'http://localhost:8983/solr/messenger/update.json/docs' --data-binary '{"word":"hello","messageid":"23523}'

我收到了以下JSON:

I received the following JSON:

{
  "responseHeader": {
    "status": 0,
    "QTime": 55
  }
}

当我转到API中的查询窗口并执行不带参数的查询时,我得到以下JSON:

When I'm going to the Query Window in the API and Execute a query without parameters I get the following JSON:

{
  {
    "responseHeader": {
      "status": 0,
      "QTime": 0,
      "params": {
        "q": "*:*",
        "indent": "on",
        "wt": "json",
        "_": "1488911768817"
      }
    },
    "response": {
      "numFound": 1,
      "start": 0,
      "docs": [
        {
          "id": "92db6722-d10d-447a-b5b1-13ad9b70b3e2",
          "_src_": "{\"word\":\"hello\",\"messageid\":\"23523\"}",
          "_version_": 1561232739042066432
        }
    }
  }
}

我的JSON是否应该看起来像下面的样子?

Shouldn't my JSON appear more like the following one?:

//More Code
"response": {
  "numFound": 1,
  "start": 0,
  "docs": [
    {
      "id": "92db6722-d10d-447a-b5b1-13ad9b70b3e2",
      "word": "hello",
      "messageid": "23523",
      "_version_": 1561232739042066432
    }
//More Code

为了以后能够通过以下选项使用参数进行过滤?

In order to be able later on to filter using parameters through the following option?:

推荐答案

事实证明,您正在使用所谓的自定义JSON索引"方法,该方法在

It turns out you were using so-called 'custom JSON indexing' approach which is described here. You can tweak it as described in the wiki in order to extract desired fields. Here is excerpt for your reference:

拆分:定义将输入JSON拆分为多个Solr文档的路径,如果单个JSON文件中包含多个文档,则必须使用此路径.如果整个JSON构成单个solr文档,则路径必须为"/".可以通过使用管道(|)分隔多个拆分路径来传递多个拆分路径,例如:split =/|/foo |/foo/bar.如果一个路径是另一个路径的子级,则它们会自动成为子级文档

split: Defines the path at which to split the input JSON into multiple Solr documents and is required if you have multiple documents in a single JSON file. If the entire JSON makes a single solr document, the path must be "/". It is possible to pass multiple split paths by separating them with a pipe (|) example : split=/|/foo|/foo/bar . If one path is a child of another, they automatically become a child document

f :这是一个多值映射参数.该参数的格式为target-field-name:json-path. json-path是必需的. target-field-name是Solr文档的字段名,并且是可选的.如果未指定,它将自动从输入JSON派生.默认目标字段名称是该字段的标准名称.可在此处使用通配符,有关更多信息,请参见下面的通配符"部分.

f: This is a multivalued mapping parameter. The format of the parameter is target-field-name:json-path. The json-path is required. The target-field-name is the Solr document field name, and is optional. If not specified, it is automatically derived from the input JSON.The default target field name is the fully qualified name of the field. Wildcards can be used here, see the section Wildcards below for more information.

但是我建议使用标准的索引文档方法,该方法来自

But I would recommend using the standard approach of indexing documents which is old good update command from here. So it would look more like:

 curl 'http://localhost:8983/solr/messenger/update?commit=true' --data-binary '{"word":"hello","messageid":"23523}' -H 'Content-type:application/json'

这篇关于Solr返回的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆