A Z 1 B
06/22/2021, 9:25 AMKishore Nallan
06/22/2021, 9:31 AMA Z 1 B
06/22/2021, 10:38 AMq = QuestionSet.all.map { |x| [x.id, <http://x.name.tr|x.name.tr>("-"," ").capitalize.to_s.squish, x.allow_for_subscriber, x.multiple_choice_questions.size] }
qs = q.map { |question_set_id, name, allow_for_subscriber, number_of_questions| { 'question_set_id' => question_set_id, 'name' => name, 'allow_for_subscriber' => allow_for_subscriber, 'number_of_questions_in_set' => number_of_questions } }
@typesense.collections['question_sets'].documents.import(qs, action: 'upsert')
A Z 1 B
06/22/2021, 10:38 AMA Z 1 B
06/22/2021, 10:38 AMschema = {
'name' => 'question_sets',
'fields' => [
{
'name' => 'question_set_id',
'type' => 'int32'
},
{
'name' => 'name',
'type' => 'string',
},
{
'name' => 'allow_for_subscriber',
'type' => 'bool',
'facet' => true
},
{
'name' => 'number_of_questions_in_set',
'type' => 'int32',
'facet' => true
},
]
}
A Z 1 B
06/22/2021, 10:38 AMKishore Nallan
06/22/2021, 10:41 AMquestion_set_id
is a regular field. You need to have a id
field. So just have id
value to be same as question_set_id
and it should work. Also id
should be a string so just convert the question_set_id
integer to string before using it as id
.