This message was deleted.
# community-help
s
This message was deleted.
a
You may be getting the fields related to the highlighted result in the
document
key along with
text_match_info
in the
hit
list result object index.
p
Ah, I made a mistake in what I wrote above. The person property of the document should have been an array of persons…
I.e.,
Copy code
{
  "id": "abc123",
  "persons": [{
    "person_id": "xyz123",
    "name": "John Smith",
    "address": "123 Some Street",
    "city": "Somerset",
    "postcode": "1234"
  }, ... ]
}
Okay, here is the schema:
Copy code
{
  "name": "houses",
  "num_documents": 0,
  "enable_nested_fields": true,
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "persons",
      "type": "object[]",
      "schema": {
        "fields": [
          {
            "name": "person_id",
            "type": "string"
          },
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "address",
            "type": "string"
          },
          {
            "name": "city",
            "type": "string"
          }
        ]
      }
    }
  ]
}
I then import the following document:
Copy code
{
  "id": "1",
  "persons": [
    {
      "person_id": "p1",
      "name": "John James Smith",
      "address": "321 Example Street",
      "city": "Oxford"
    }
  ]
}
When I query
?q=james&query_by=persons.name
I get the following result:
Copy code
{
  "facet_counts": [],
  "found": 1,
  "hits": [
    {
      "document": {
        "id": "1",
        "persons": [
          {
            "address": "321 Example Street",
            "city": "Oxford",
            "name": "John James Smith",
            "person_id": "p1"
          }
        ]
      },
      "highlight": {
        "persons": [
          {
            "name": {
              "matched_tokens": [
                "James"
              ],
              "snippet": "John <mark>James</mark> Smith"
            }
          }
        ]
      },
      "highlights": [],
      "text_match": 578730123365187700,
      "text_match_info": {
        "best_field_score": "1108091338752",
        "best_field_weight": 15,
        "fields_matched": 1,
        "score": "578730123365187705",
        "tokens_matched": 1
      }
    }
  ],
  "out_of": 1,
  "page": 1,
  "request_params": {
    "collection_name": "houses",
    "per_page": 10,
    "q": "james"
  },
  "search_cutoff": false,
  "search_time_ms": 1
}
Can I get the person_id of the highlighted person?
On a different note, the fields in your schema should be
persons.name
,
persons.address
and
persons.city
...
p
@Jason Bosco Thanks, Jason. Sorry to revive an old thread, but you are saying that the
schema
specification I did for a nested object is invalid? So the fields are essentially not indexed the way I did it?
j
That’s correct. In fact it should have errored out since the fields are not set as optional
🙏 1