2

I have a document (document type A) which has multiple (any number of) children documents of the same type (document type B). The following link from vespa documentation talks about the parent-child relationship.

http://docs.vespa.ai/documentation/search-definitions.html#document-references

For this, we have to define a reference type field and then import any field from the referred document. What if I want multiple document references from the parent document. Can't I define something like,

field child_ref type array<reference<doc_type_child>> {
      indexing: attribute
}

certainly, I would have the difficulty of importing a certain field as all the child references have the same field.

Let's say the child document type is model and parent document type is car, basically, I want to have a nested document in which I need the capability of querying based on parent and child fields also. Let's say if I search for Mercedes cars with spokes of wheels in range (3,5), the search for Mercedes brand (parent doc field) in parent documents and further I would like to choose models of Mercedes car results (car1, car2, ...) which have wheel spokes (child doc field) from 3 to 5, (car1[model 1, model 4, model 6], car2[model 2, model 3, model 5]). Basically, hits should be of Mercedes brand and in all those hits, internally hits of models which have 3-5 wheel spokes.

vandit.thakkar
  • 121
  • 1
  • 1
  • 6

1 Answers1

4

The relationship goes from the child document to the parent so no you cannot store child document references in the parent document.

But the example you provide is fully doable with car being the parent (global) document type and model the child, each child document references the parent (car) and can import any field from the parent document type while matching/searching is performed against the child (model) document type and you can search both model document fields and the imported parent car fields. /search/?query=car_brand:mercedes+AND+model_spokes:[3;5]&restrict=model

Where car_brand is an imported field from the parent car in the model document type.

Jo Kristian Bergum
  • 2,984
  • 5
  • 8
  • I had thought of this solution very initially and that makes sense of parent-child relationship certainly. But as we can't import indexed fields from parent doc, I am not able to execute this query /search/?query=car_brand:mercedes+AND+model_spokes:[3;5]&restrict=model . I have car_brand field as index field in parent document. – vandit.thakkar Apr 04 '18 at 12:40
  • 1
    You are right that only attribute fields can be imported from the parent document type but attribute fields also supports searches but only using match:word instead of match:text (tokenized). See http://docs.vespa.ai/documentation/attributes.html and http://docs.vespa.ai/documentation/reference/search-definitions-reference.html#match – Jo Kristian Bergum Apr 05 '18 at 11:15