Подтвердить что ты не робот

Как индексировать и искать вложенные Json в Solr 4.9.0

Я хочу индексировать и искать вложенный json в solr. Вот мой код json

{
        "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"
        }
    }
4b9b3361

Ответ 1

Вложенные дочерние документы в документ. Вы должны использовать правильный синтаксис для вложенных дочерних документов в 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"
      }
    ]
  }
]

Посмотрите на статью , в которой описываются дочерние документы JSON и объединения блоков.

Ответ 2

Используя формат, указанный @qux, вы столкнетесь с "Expected: OBJECT_START but got ARRAY_START at [16]", "code": 400 как когда JSON, начинающийся с [....], анализируется как массив JSON

{
        "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"
        }
    }

Ответ 3

см. синтаксис в http://yonik.com/solr-nested-objects/

$ curl http://localhost:8983/solr/demo/update?commitWithin=3000 -d '
[
 {id : book1, type_s:book, title_t : "The Way of Kings", author_s : "Brandon Sanderson",
  cat_s:fantasy, pubyear_i:2010, publisher_s:Tor,
  _childDocuments_ : [
    { id: book1_c1, type_s:review, review_dt:"2015-01-03T14:30:00Z",
      stars_i:5, author_s:yonik,
      comment_t:"A great start to what looks like an epic series!"
    }
    ,
    { id: book1_c2, type_s:review, review_dt:"2014-03-15T12:00:00Z",
      stars_i:3, author_s:dan,
      comment_t:"This book was too long."
    }
  ]
 }
]'

поддерживается из solr 5.3