2

I need to create a search definition file in Vespa where I can a JSON array inside JSON object with all fields searchable

for example-

{
  "department": "education",
  "designation": "student",
  "person": {
    "name": "steve",
    "city": "delhi",
    "hobbies": [
      {
        "hobbyName": "cricket",
        "type": "outdoor"
      },
      {
        "hobbyName": "chess",
        "type": "indoor"
      }
    ]
  }
}

Here I need to search for a person.name, person.city, person.hobbies.hobbyName, person.hobbies.type.

suyash308
  • 347
  • 1
  • 7

1 Answers1

3

Using array of struct , something like this should get you started:

search person {

    document person {

        field name type string {
            indexing: summary | index
        }

        field city type string {
            indexing: summary | index
        }

        struct hobby {
            field hobbyName type string {}
            field type      type string {}
        }

        field hobbies type array<hobby> {
            indexing: summary
            struct-field hobbyName { indexing: attribute }
            struct-field type      { indexing: attribute }
        }
    }
}
Kristian Aune
  • 876
  • 5
  • 5
  • The "person" is already inside a JSON object, I have modified the question, please have a look. – suyash308 Jan 22 '20 at 08:11
  • A subtlety of Vespa is, you can search in array of struct but not struct. It seems the record _is_ a person, and only one, so the person struct is not needed. You can rename fields to person_name, person_city and person_hobbies to make it clearer – Kristian Aune Jan 22 '20 at 08:26