Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Index & Search Nested Json in Solr 4.9.0

Tags:

json

solr

I want to index & search nested json in solr. Here is my json code

{
        "id": "44444",
        "headline": "testing US",
        "generaltags": [
            {
                "type": "person",
                "name": "Jayalalitha",
                "relevance": "0.334",
                "count": 1
            },
            {
                "type": "person",
                "name": "Kumar",
                "relevance": "0.234",
                "count": 1
            }
        ],
        "socialtags": {
            "type": "SocialTag",
            "name": "US",
            "importance": 2
        },
        "topic": {
            "type": "Topic",
            "name": "US",
            "score": "0.936"
        }
    }

When I try to Index, I'm getting the error "Error parsing JSON field value. Unexpected OBJECT_START"

When we tried to use Multivalued Field & index, we couldn't able to search using the multivalued field? Its returning "Undefined Field"

Also Please advice if I need to do any changes in schema.xml file?

like image 797
w3lessons Avatar asked Oct 15 '14 15:10

w3lessons


People also ask

What is an index in an essay?

An index is a list of all the names, subjects and ideas in a piece of written work, designed to help readers quickly find where they are discussed in the text. Usually found at the end of the text, an index doesn't just list the content (that's what a table of contents is for), it analyses it.


1 Answers

You are nesting child documents within your document. You need to use the proper syntax for nested child documents in JSON:

[
  {
    "id": "1",
    "title": "Solr adds block join support",
    "content_type": "parentDocument",
    "_childDocuments_": [
      {
        "id": "2",
        "comments": "SolrCloud supports it too!"
      }
    ]
  },
  {
    "id": "3",
    "title": "Lucene and Solr 4.5 is out",
    "content_type": "parentDocument",
    "_childDocuments_": [
      {
        "id": "4",
        "comments": "Lots of new features"
      }
    ]
  }
]

Have a look at this article which describes JSON child documents and block joins.

like image 66
qux Avatar answered Oct 01 '22 17:10

qux