I store survey responses in my ES, so what happens is that the people use the mobile app to fill survey forms those form responses are sent to the backend and then stored in the ES like this, this is how answers to the questions in a form are store
answers {
"uKeCywV4SAgD8YGReSkn" : {
"_id" : "b465de5e-5468-40fe-8a8d-fc02083",
"responseVersionNumber" : 1,
"options" : [
{
"id" : "32700fb5-51d2-4617-b65f-831b83c88080"
},
{
"id" : "32700fb5-51d2-4617-b65f-831b83c87777"
}
}
the answers doc contains the answers for each question under its question ID. The string that you see below is the question ID, in the same way all the other answers are stored in ES under their respective question IDs in their respective for doc for that response.
Now I want to search over these answers, the above answer response is of mcq multi-select type, as you can see the text field (that contains) the answer values (i.e. hobbies of the user Gardening and Sports) and the options id array both can be used for this, I can either send the options id array from my web app to ES or the text values (or option labels as we call them) and also using the questions IDs so for example let say I have a question with id q1 so I want my query to say that give me the docs where question q1 has both answers a1 and a2
I have been wanting to explore the options id approach this is a sample query that I build for it.
{
"_source": {"includes": ["answers.uKeCywV4SAgD8YGReSkn.text", "answers.uKeCywV4SAgD8YGReSkn.questionTypeCode"]},
"query": {
"bool": {
"filter": [{
"bool": {
"must": [{
"match": {
"answers.uKeCywV4SAgD8YGReSkn.options.id": "32700fb5-51d2-4617-b65f-831b83c88080"
}
},
{
"match": {
"answers.uKeCywV4SAgD8YGReSkn.options.id": "32700fb5-51d2-4617-b65f-831b83c87777"
}
}
]
}
}, {
"match": {
"formId": "hHhcLKh9st1vFr8nDY4a"
}
}, {
"range": {
"_updated_at": {
"from": "1970-01-01T00:00:00.000+0000",
"include_lower": true,
"include_upper": true,
"to": null
}
}
}]
}
}
}
I wanted to know if there are any drawbacks for going with this approach instead of searching the text field using both the options labels
According to the mapping this is how both the fields are set
"questionId": {
"type": "keyword",
"index": false
},
"text": {
"type": "text"
},
"options": {
"enabled": false
},